Skip to content

Commit 0ff32f2

Browse files
committed
!3 Websocket 应用
Merge pull request !3 from lisgroup/develop
2 parents b2c5f34 + 5544035 commit 0ff32f2

39 files changed

+382
-37
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ npm run dev
138138

139139
# 打包(可选)
140140
npm run build
141-
# 将 dist 目录下的文件 copy 到 php/public 目录。
142141
```
142+
~~npm run build 命令会自动将 dist 目录下的文件 copy 到 laravel/public 目录下。~~
143143

144144
## 域名绑定
145145
域名需要绑定到根目录,即项目的 laravel/public 目录下。
@@ -149,7 +149,7 @@ npm run build
149149
```shell
150150
server {
151151
listen 443 ssl;
152-
root /www/vueBus/laravel/public;
152+
root /www/laravel-vue-admin/laravel/public;
153153
server_name www.guke1.com; # 改为绑定证书的域名
154154

155155
# ssl 配置
@@ -217,8 +217,8 @@ upstream laravels {
217217
server {
218218
listen 80;
219219
# 别忘了绑Host哟
220-
server_name www.bus.com;
221-
root /home/www/vueBus/laravel/public;
220+
server_name www.guke1.com;
221+
root /home/www/laravel-vue-admin/laravel/public;
222222
access_log /home/wwwlogs/nginx/$server_name.access.log;
223223
autoindex off;
224224
index index.html index.htm;

admin/src/api/config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import request from '@/utils/request'
2+
3+
export function getList(params) {
4+
return request({
5+
url: '/api/config',
6+
method: 'get',
7+
params
8+
})
9+
}
10+
11+
export function postAdd(params) {
12+
return request.post('/api/config', params)
13+
}
14+
15+
export function edit(id) {
16+
return request.get('/api/config/' + id)
17+
}
18+
19+
export function postEdit(id, params) {
20+
return request.patch('/api/config/' + id, params)
21+
}
22+
23+
export function deleteAct(id) {
24+
return request.delete('/api/config/' + id)
25+
}
26+
27+
/**
28+
* 搜索 config
29+
* @param params
30+
*/
31+
export function search(params) {
32+
return request({
33+
url: '/api/config_search',
34+
method: 'get',
35+
params
36+
})
37+
}

admin/src/router/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export const routeSuper = [
137137
{
138138
path: 'config',
139139
name: '配置管理',
140-
component: () => import('@/views/lines/index'),
140+
component: () => import('@/views/config/index'),
141141
meta: { title: '配置列表', icon: 'table', roles: [Super] }
142142
},
143143
{

admin/src/views/api_excel/index.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ export default {
157157
},
158158
created() {
159159
this.listQuery = this.$route.query
160-
this.currentpage = parseInt(this.listQuery.page)
160+
const page = parseInt(this.listQuery.page)
161+
this.currentpage = isNaN(page) ? 1 : page
161162
const perPage = parseInt(this.$route.query.perPage)
162163
this.perpage = isNaN(perPage) ? this.perpage : perPage
163164
// this.fetchData()
@@ -222,7 +223,7 @@ export default {
222223
},
223224
initWebSocket() { // 初始化 weosocket
224225
if ('WebSocket' in window) {
225-
const url = process.env.WEBSOCKET + '?action=api_excel&token=' + getToken()
226+
const url = process.env.WEBSOCKET + '?action=api_excel&token=' + getToken() + '&page=' + this.currentpage + '&perPage=' + this.perpage
226227
this.websock = new WebSocket(url)
227228
this.websock.onmessage = this.onmessage
228229
this.websock.onopen = this.onopen

admin/src/views/config/index.vue

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<template>
2+
<div class="app-container">
3+
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
4+
<el-form-item label="名称" prop="name">
5+
<el-input v-model="form.name"/>
6+
</el-form-item>
7+
<el-form-item label="开启新老接口" prop="default_open">
8+
<el-col :span="4">
9+
<el-input v-model="form.default_open"/>
10+
</el-col>
11+
<el-col :span="20">&nbsp;开启公交配置情况--【1: 老接口,2: 新接口,3: 先老接口再新接口,4: 先新接口后老接口】</el-col>
12+
</el-form-item>
13+
<el-form-item label="是否启用">
14+
<el-switch v-model="form.state"/>
15+
</el-form-item>
16+
<el-form-item>
17+
<el-button type="primary" @click="onSubmit('form')">提交</el-button>
18+
<el-button @click="resetForm('form')">重置</el-button>
19+
</el-form-item>
20+
</el-form>
21+
</div>
22+
</template>
23+
24+
<script>
25+
import { postAdd, getList } from '@/api/config'
26+
27+
export default {
28+
data() {
29+
return {
30+
form: {
31+
name: '',
32+
default_open: 1,
33+
state: true,
34+
loading: false
35+
},
36+
rules: {
37+
name: [
38+
{ required: true, message: '请输入名称', trigger: 'blur' }
39+
],
40+
default_open: [
41+
{ required: true, message: '请输入开启公交配置情况', trigger: 'blur' }
42+
]
43+
},
44+
redirect: '/config/index'
45+
}
46+
},
47+
created() {
48+
this.init()
49+
},
50+
methods: {
51+
init() {
52+
const that = this
53+
getList({ perPage: 20 }).then(response => {
54+
const data = response.data
55+
that.form.name = data.name
56+
that.form.default_open = data.default_open
57+
})
58+
},
59+
onSubmit(form) {
60+
// console.log(this.form)
61+
this.$refs[form].validate((valid) => {
62+
if (valid) {
63+
this.loading = true
64+
postAdd(this.form).then(response => {
65+
// console.log(response)
66+
this.loading = false
67+
if (response.code === 200) {
68+
this.$message({
69+
message: '操作成功',
70+
type: 'success'
71+
})
72+
// this.$router.push({ path: this.redirect || '/' })
73+
} else {
74+
this.$message.error(response.reason)
75+
}
76+
})
77+
} else {
78+
// this.$message('error submit!')
79+
// console.log('error submit!!')
80+
return false
81+
}
82+
})
83+
},
84+
onCancel() {
85+
this.$message({
86+
message: 'cancel!',
87+
type: 'warning'
88+
})
89+
},
90+
resetForm(formName) {
91+
this.$refs[formName].resetFields()
92+
}
93+
}
94+
}
95+
</script>
96+
97+
<style scoped>
98+
.line {
99+
text-align: center;
100+
}
101+
</style>
102+

laravel/app/Http/Controllers/Api/ArticleController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(Request $request)
4242
*/
4343
public function index()
4444
{
45-
$list = Article::orderBy('id', 'DESC')->paginate($this->perPage);
45+
$list = Article::orderBy('id', 'DESC')->select('id', 'title', 'author', 'keywords', 'created_at')->paginate($this->perPage);
4646
return $this->out(200, $list);
4747
}
4848

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api;
4+
5+
use App\Models\Config;
6+
use App\Http\Controllers\Controller;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Support\Facades\Cache;
9+
10+
class ConfigController extends Controller
11+
{
12+
/**
13+
* @var int 默认分页条数
14+
*/
15+
public $perPage = 10;
16+
17+
private $allow = ['name', 'title', 'default_open', 'state'];
18+
19+
/**
20+
* Create a new AuthController instance.
21+
* 要求附带email和password(数据来源users表)
22+
*
23+
* @return void
24+
*/
25+
public function __construct(Request $request)
26+
{
27+
// 这里额外注意了:官方文档样例中只除外了『login』
28+
// 这样的结果是,token 只能在有效期以内进行刷新,过期无法刷新
29+
// 如果把 refresh 也放进去,token 即使过期但仍在刷新期以内也可刷新
30+
// 不过刷新一次作废
31+
$this->middleware(['auth:api', 'role']);
32+
// 另外关于上面的中间件,官方文档写的是『auth:api』
33+
// 但是我推荐用 『jwt.auth』,效果是一样的,但是有更加丰富的报错信息返回
34+
35+
$perPage = intval($request->input('perPage'));
36+
$this->perPage = $perPage ?? 11;
37+
}
38+
39+
/**
40+
* Display a listing of the resource.
41+
*
42+
* @return \Illuminate\Http\Response
43+
*/
44+
public function index()
45+
{
46+
$list = [];
47+
foreach ($this->allow as $item) {
48+
$list[$item] = Cache::get($item) ?? '';
49+
}
50+
return $this->out(200, $list);
51+
}
52+
53+
/**
54+
* Show the form for creating a new resource.
55+
*
56+
* @return \Illuminate\Http\Response
57+
*/
58+
public function create()
59+
{
60+
return $this->out(200, ['method' => 'create']);
61+
}
62+
63+
/**
64+
* Store a newly created resource in storage.
65+
* 新增入库操作
66+
*
67+
* @param Request $request
68+
* @return \Illuminate\Http\Response
69+
*/
70+
public function store(Request $request)
71+
{
72+
// 全部数据
73+
$input = $request->all();
74+
// 存入缓存数据
75+
foreach ($input as $key => $item) {
76+
if (in_array($key, $this->allow)) {
77+
Cache::forever($key, $item);
78+
}
79+
}
80+
return $this->out(200);
81+
}
82+
83+
/**
84+
* Display the specified resource.
85+
* 展示某个详情数据
86+
*
87+
* @param Config $Config
88+
*
89+
* @return \Illuminate\Http\Response
90+
*/
91+
public function show(Config $Config)
92+
{
93+
return $this->out(200, $Config);
94+
}
95+
96+
/**
97+
* Show the form for editing the specified resource.
98+
* 编辑展示数据
99+
*
100+
* @param int $id
101+
*
102+
* @return \Illuminate\Http\Response
103+
*/
104+
public function edit($id)
105+
{
106+
$data = Config::findOrFail($id);
107+
return $this->out(200, $data);
108+
}
109+
110+
/**
111+
* Update the specified resource in storage.
112+
* 更新数据
113+
*
114+
* @param Request $request
115+
* @param int $id
116+
* @return \Illuminate\Http\Response
117+
*/
118+
public function update(Request $request, $id)
119+
{
120+
$input = $request->all();
121+
// $model = new Config();$model->save($input, ['id' => $id]);
122+
// 老版本更新操作如下,新版本先查询再更新
123+
// Config::where('id', $id)->update($input)
124+
$Config = Config::findOrFail($id);
125+
if ($Config->update($input)) {
126+
return $this->out(200, ['data' => ['id' => $id]]);
127+
} else {
128+
return $this->out(4000);
129+
}
130+
}
131+
132+
/**
133+
* Remove the specified resource from storage.
134+
*
135+
* @param int $id
136+
* @return \Illuminate\Http\Response
137+
* @throws \Exception
138+
*/
139+
public function destroy($id)
140+
{
141+
if (Config::findOrFail($id)->delete()) {
142+
$data = ['msg' => '删除成功', 'errno' => 0];
143+
} else {
144+
$data = ['msg' => '删除失败', 'errno' => 2];
145+
}
146+
return $this->out(200, $data);
147+
}
148+
}

laravel/app/Http/Controllers/Bus/AutoController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AutoController extends Controller
1818

1919
public function __construct()
2020
{
21-
$this->http = Http::getInstent();
21+
$this->http || $this->http = Http::getInstent();
2222
}
2323
/**
2424
* 获取七牛 Token 的方法

0 commit comments

Comments
 (0)