Skip to content

Commit 1f8a7f0

Browse files
committed
update(view): role
1 parent 095cb55 commit 1f8a7f0

File tree

4 files changed

+127
-152
lines changed

4 files changed

+127
-152
lines changed

admin/src/api/role.js

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

admin/src/views/role/add.vue

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,21 @@
11
<template>
22
<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"/>
3+
<el-form ref="form" :model="form" :rules="rules" label-width="220px">
4+
<el-form-item label="角色名称" prop="name">
5+
<el-col :span="10">
6+
<el-input v-model="form.name"/>
7+
</el-col>
8+
<el-col :span="14"/>
69
</el-form-item>
7-
<el-form-item label="接口地址" prop="url">
8-
<el-input v-model="form.url"/>
9-
</el-form-item>
10-
<el-form-item label="接口参数" prop="param">
11-
<el-input v-model="form.param"/>
12-
<span>(多个参数请用英文 , 分割;如: realname,mobile,idcard)</span>
13-
</el-form-item>
14-
<el-form-item label="结果集 result" prop="result">
15-
<el-input v-model="form.result"/>
16-
<span>(多个参数请用英文 , 分割;如: res,msg)</span>
17-
</el-form-item>
18-
<el-form-item label="是否处理" prop="is_need">
19-
<el-switch v-model="form.is_need"/>
20-
<br>
21-
<span>(开启后,输出的 Excel 最后一栏将根据 result 字段 res 1 展示一致 2 不一致)</span>
22-
</el-form-item>
23-
<el-form-item label="网址" prop="website">
24-
<el-input v-model="form.website"/>
25-
</el-form-item>
26-
<el-form-item label="请求方式" prop="method">
27-
<!--<el-input v-model="form.method"/>-->
28-
<el-select v-model="form.method" placeholder="请选择接口" value-key="name">
29-
<el-option key="1" label="get" value="get">
30-
<span style="float: left; color: #8492a6; font-size: 13px">get</span>
31-
</el-option>
32-
<el-option key="2" label="post" value="post">
33-
<span style="float: left; color: #8492a6; font-size: 13px">post</span>
34-
</el-option>
35-
</el-select>
36-
</el-form-item>
37-
<el-form-item label="是否启用">
38-
<el-switch v-model="form.state"/>
10+
11+
<el-form-item label="新增角色赋值权限" prop="roles">
12+
<template>
13+
<el-checkbox-group v-model="form.checkedPermissions" @change="PerChange">
14+
<el-checkbox v-for="permission in form.permissions" :label="permission.id" :key="permission.id">{{ permission.name }}</el-checkbox>
15+
</el-checkbox-group>
16+
</template>
3917
</el-form-item>
18+
4019
<el-form-item>
4120
<el-button type="primary" @click="onSubmit('form')">提交</el-button>
4221
<el-button @click="resetForm('form')">重置</el-button>
@@ -46,43 +25,43 @@
4625
</template>
4726

4827
<script>
49-
import { postAdd } from '@/api/api_param'
28+
29+
import { postAdd, getPermission } from '@/api/role'
5030
5131
export default {
5232
data() {
5333
return {
5434
form: {
5535
name: '',
56-
url: '',
57-
param: '',
58-
result: '',
59-
is_need: false,
60-
state: true,
61-
website: '',
62-
method: 'get',
36+
checkedPermissions: [],
37+
permissions: [],
38+
isIndeterminate: true,
6339
loading: false
6440
},
6541
rules: {
6642
name: [
6743
{ required: true, message: '请输入名称', trigger: 'blur' }
68-
],
69-
url: [
70-
{ required: true, message: '请输入接口地址', trigger: 'blur' }
71-
],
72-
param: [
73-
{ required: true, message: '请输入接口参数', trigger: 'blur' }
74-
],
75-
result: [
76-
{ required: true, message: '请输入结果集 result', trigger: 'blur' }
77-
],
78-
is_need: [
79-
{ required: true, message: '请选择是否处理', trigger: 'blur' }
8044
]
8145
},
82-
redirect: '/api_param/index'
46+
redirect: '/role'
8347
}
8448
},
49+
created() {
50+
this.fetchData()
51+
},
8552
methods: {
53+
fetchData() {
54+
this.listLoading = true
55+
getPermission().then(response => {
56+
console.log(response.data)
57+
this.form.permissions = response.data.permissions
58+
this.listLoading = false
59+
})
60+
},
61+
PerChange(value) {
62+
const checkedCount = value.length
63+
this.isIndeterminate = checkedCount > 0 && checkedCount < this.form.permissions.length
64+
},
8665
onSubmit(form) {
8766
console.log(this.form)
8867
this.$refs[form].validate((valid) => {
@@ -126,4 +105,3 @@ export default {
126105
text-align: center;
127106
}
128107
</style>
129-

admin/src/views/role/edit.vue

Lines changed: 34 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,21 @@
11
<template>
22
<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"/>
3+
<el-form ref="form" :model="form" :rules="rules" label-width="220px">
4+
<el-form-item label="角色名称" prop="name">
5+
<el-col :span="10">
6+
<el-input v-model="form.name"/>
7+
</el-col>
8+
<el-col :span="14"/>
69
</el-form-item>
7-
<el-form-item label="接口地址" prop="url">
8-
<el-input v-model="form.url"/>
9-
</el-form-item>
10-
<el-form-item label="接口参数" prop="param">
11-
<el-input v-model="form.param"/>
12-
<span>(多个参数请用英文 , 分割;如: realname,mobile,idcard)</span>
13-
</el-form-item>
14-
<el-form-item label="结果集 result" prop="result">
15-
<el-input v-model="form.result"/>
16-
<span>(多个参数请用英文 , 分割;如: res,msg)</span>
17-
</el-form-item>
18-
<el-form-item label="是否处理" prop="is_need">
19-
<el-switch v-model="form.is_need"/>
20-
</el-form-item>
21-
<el-form-item label="网址" prop="website">
22-
<el-input v-model="form.website"/>
23-
</el-form-item>
24-
<el-form-item label="请求方式" prop="method">
25-
<!--<el-input v-model="form.method"/>-->
26-
<el-select v-model="form.method" placeholder="请选择接口" value-key="name">
27-
<el-option key="1" label="get" value="get">
28-
<span style="float: left; color: #8492a6; font-size: 13px">get</span>
29-
</el-option>
30-
<el-option key="2" label="post" value="post">
31-
<span style="float: left; color: #8492a6; font-size: 13px">post</span>
32-
</el-option>
33-
</el-select>
34-
</el-form-item>
35-
<el-form-item label="是否启用">
36-
<el-switch v-model="form.state"/>
10+
11+
<el-form-item label="新增角色赋值权限" prop="roles">
12+
<template>
13+
<el-checkbox-group v-model="form.checkedPermissions" @change="PerChange">
14+
<el-checkbox v-for="permission in form.permissions" :label="permission.id" :key="permission.id">{{ permission.name }}</el-checkbox>
15+
</el-checkbox-group>
16+
</template>
3717
</el-form-item>
18+
3819
<el-form-item>
3920
<el-button type="primary" @click="onSubmit('form')">提交</el-button>
4021
<el-button @click="resetForm('form')">重置</el-button>
@@ -44,63 +25,56 @@
4425
</template>
4526

4627
<script>
47-
import { edit, postEdit } from '@/api/api_param'
28+
import { postEdit, edit, getPermission } from '@/api/role'
4829
4930
export default {
5031
data() {
5132
return {
5233
form: {
5334
name: '',
54-
url: '',
55-
param: '',
56-
result: '',
57-
is_need: false,
58-
state: true,
59-
website: '',
60-
method: 'get',
35+
checkedPermissions: [],
36+
permissions: [],
37+
isIndeterminate: true,
6138
loading: false
6239
},
6340
rules: {
6441
name: [
6542
{ required: true, message: '请输入名称', trigger: 'blur' }
66-
],
67-
url: [
68-
{ required: true, message: '请输入接口地址', trigger: 'blur' }
69-
],
70-
param: [
71-
{ required: true, message: '请输入接口参数', trigger: 'blur' }
72-
],
73-
result: [
74-
{ required: true, message: '请输入结果集 result', trigger: 'blur' }
75-
],
76-
is_need: [
77-
{ required: true, message: '请选择是否处理', trigger: 'blur' }
7843
]
7944
},
80-
redirect: '/api_param/index'
45+
redirect: '/role'
8146
}
8247
},
8348
created() {
8449
this.id = this.$route.params.id
8550
this.getData(this.id)
51+
this.fetchData()
8652
},
8753
methods: {
8854
getData(id) {
89-
// this.id = this.$route.params.id
9055
edit(id).then(response => {
91-
// console.log(response)
9256
this.loading = false
9357
if (response.code === 200) {
94-
this.form = response.data
95-
this.form.is_need = (response.data.is_need === 1)
96-
this.form.state = (response.data.state === 1)
58+
this.form.name = response.data.name
9759
} else {
9860
this.$message.error(response.reason)
9961
}
10062
})
10163
},
64+
fetchData() {
65+
this.listLoading = true
66+
getPermission().then(response => {
67+
console.log(response.data)
68+
this.form.permissions = response.data.permissions
69+
this.listLoading = false
70+
})
71+
},
72+
PerChange(value) {
73+
const checkedCount = value.length
74+
this.isIndeterminate = checkedCount > 0 && checkedCount < this.form.permissions.length
75+
},
10276
onSubmit(form) {
103-
console.log(this.form)
77+
// console.log(this.form)
10478
this.$refs[form].validate((valid) => {
10579
if (valid) {
10680
this.loading = true
@@ -142,4 +116,3 @@ export default {
142116
text-align: center;
143117
}
144118
</style>
145-

0 commit comments

Comments
 (0)