Skip to content

Commit 6710b4f

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 71b986e + 206af1a commit 6710b4f

File tree

5 files changed

+276
-1
lines changed

5 files changed

+276
-1
lines changed

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/config/index.vue

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 } 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+
methods: {
48+
onSubmit(form) {
49+
// console.log(this.form)
50+
this.$refs[form].validate((valid) => {
51+
if (valid) {
52+
this.loading = true
53+
postAdd(this.form).then(response => {
54+
// console.log(response)
55+
this.loading = false
56+
if (response.code === 200) {
57+
this.$message({
58+
message: '操作成功',
59+
type: 'success'
60+
})
61+
this.$router.push({ path: this.redirect || '/' })
62+
} else {
63+
this.$message.error(response.reason)
64+
}
65+
})
66+
} else {
67+
// this.$message('error submit!')
68+
// console.log('error submit!!')
69+
return false
70+
}
71+
})
72+
},
73+
onCancel() {
74+
this.$message({
75+
message: 'cancel!',
76+
type: 'warning'
77+
})
78+
},
79+
resetForm(formName) {
80+
this.$refs[formName].resetFields()
81+
}
82+
}
83+
}
84+
</script>
85+
86+
<style scoped>
87+
.line {
88+
text-align: center;
89+
}
90+
</style>
91+
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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+
9+
class ConfigController extends Controller
10+
{
11+
/**
12+
* @var int 默认分页条数
13+
*/
14+
public $perPage = 10;
15+
16+
/**
17+
* Create a new AuthController instance.
18+
* 要求附带email和password(数据来源users表)
19+
*
20+
* @return void
21+
*/
22+
public function __construct(Request $request)
23+
{
24+
// 这里额外注意了:官方文档样例中只除外了『login』
25+
// 这样的结果是,token 只能在有效期以内进行刷新,过期无法刷新
26+
// 如果把 refresh 也放进去,token 即使过期但仍在刷新期以内也可刷新
27+
// 不过刷新一次作废
28+
$this->middleware(['auth:api', 'role']);
29+
// 另外关于上面的中间件,官方文档写的是『auth:api』
30+
// 但是我推荐用 『jwt.auth』,效果是一样的,但是有更加丰富的报错信息返回
31+
32+
$perPage = intval($request->input('perPage'));
33+
$this->perPage = $perPage ?? 11;
34+
}
35+
36+
/**
37+
* Display a listing of the resource.
38+
*
39+
* @return \Illuminate\Http\Response
40+
*/
41+
public function index()
42+
{
43+
$list = Config::orderBy('sort')->paginate($this->perPage);
44+
return $this->out(200, $list);
45+
}
46+
47+
/**
48+
* Show the form for creating a new resource.
49+
*
50+
* @return \Illuminate\Http\Response
51+
*/
52+
public function create()
53+
{
54+
return $this->out(200, ['method' => 'create']);
55+
}
56+
57+
/**
58+
* Store a newly created resource in storage.
59+
* 新增入库操作
60+
*
61+
* @param Request $request
62+
* @return \Illuminate\Http\Response
63+
*/
64+
public function store(Request $request)
65+
{
66+
// 会出现 Unknown column 'guid' in 'field list' 不存在的字段入库报错问题
67+
// $rs = Config::insert($request->all());
68+
$input = $request->all();
69+
is_null($input['sort']) && $input['sort'] = 100;
70+
$model = new Config($input);
71+
if ($model->save()) {
72+
return $this->out(200, ['data' => ['id' => $model->id]]);
73+
} else {
74+
return $this->out(4000);
75+
}
76+
77+
}
78+
79+
/**
80+
* Display the specified resource.
81+
* 展示某个详情数据
82+
*
83+
* @param Config $Config
84+
*
85+
* @return \Illuminate\Http\Response
86+
*/
87+
public function show(Config $Config)
88+
{
89+
return $this->out(200, $Config);
90+
}
91+
92+
/**
93+
* Show the form for editing the specified resource.
94+
* 编辑展示数据
95+
*
96+
* @param int $id
97+
*
98+
* @return \Illuminate\Http\Response
99+
*/
100+
public function edit($id)
101+
{
102+
$data = Config::findOrFail($id);
103+
return $this->out(200, $data);
104+
}
105+
106+
/**
107+
* Update the specified resource in storage.
108+
* 更新数据
109+
*
110+
* @param Request $request
111+
* @param int $id
112+
* @return \Illuminate\Http\Response
113+
*/
114+
public function update(Request $request, $id)
115+
{
116+
$input = $request->all();
117+
// $model = new Config();$model->save($input, ['id' => $id]);
118+
// 老版本更新操作如下,新版本先查询再更新
119+
// Config::where('id', $id)->update($input)
120+
$Config = Config::findOrFail($id);
121+
if ($Config->update($input)) {
122+
return $this->out(200, ['data' => ['id' => $id]]);
123+
} else {
124+
return $this->out(4000);
125+
}
126+
}
127+
128+
/**
129+
* Remove the specified resource from storage.
130+
*
131+
* @param int $id
132+
* @return \Illuminate\Http\Response
133+
* @throws \Exception
134+
*/
135+
public function destroy($id)
136+
{
137+
if (Config::findOrFail($id)->delete()) {
138+
$data = ['msg' => '删除成功', 'errno' => 0];
139+
} else {
140+
$data = ['msg' => '删除失败', 'errno' => 2];
141+
}
142+
return $this->out(200, $data);
143+
}
144+
}

laravel/routes/api.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
Route::get('roles/store', 'RoleController@store');
5252
Route::resource('permissions', 'PermissionController');
5353
Route::resource('roles', 'RoleController');
54+
55+
// 配置相关
56+
Route::resource('config', 'Api\ConfigController');
5457
});
5558

5659

0 commit comments

Comments
 (0)