This commit is contained in:
吕金泽
2021-10-24 20:09:53 +08:00
commit 4a7d1d08ac
509 changed files with 142640 additions and 0 deletions
@@ -0,0 +1,126 @@
<template>
<el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="120px" style="width: 400px; margin-left:50px;">
<el-form-item label="登录名称" prop="username">
<el-input v-model="temp.username" />
</el-form-item>
<el-form-item label="姓名/昵称" prop="name">
<el-input v-model="temp.name" />
</el-form-item>
<el-form-item label="密码" prop="password">
<el-input v-model="temp.password" />
</el-form-item>
<el-form-item label="手机号" prop="phone">
<el-input v-model="temp.phone" />
</el-form-item>
<el-form-item label="禁止登录" prop="isLogin">
<template>
<el-switch
v-model="temp.isLogin"
:active-value="1"
:inactive-value="0"
/>
</template>
</el-form-item>
<el-form-item label="选择角色">
<el-checkbox-group v-model="selectRoles" size="small">
<el-checkbox v-for="role in roles" :key="role.id" :label="role.id">{{ role.name }}</el-checkbox>
</el-checkbox-group>
</el-form-item>
</el-form>
</template>
<script>
export default {
name: 'UserForm',
props: {
visible: {
type: Boolean,
default: false
},
dialogStatus: {
type: String,
default: ''
}
},
data() {
return {
rules: {
username: [{ required: true, message: '请输入登录名称', trigger: 'change' }]
},
roles: [],
selectRoles: [],
temp: this.getTemp()
}
},
computed: {
dialogVisible: {
get() {
return this.visible
},
set(val) {
this.$emit('update:visible', val)
}
}
},
watch: {
visible(newVal) {
this.temp = this.getTemp()
this.$nextTick(() => {
this.$refs['dataForm'].clearValidate()
})
}
},
created() {
this.$get('role/list?size=999999').then(response => {
const { data } = response
this.roles = data.list
})
},
methods: {
getTemp() {
return {
id: '',
name: '',
username: '',
password: '',
phone: '',
isLogin: 0,
roles: []
}
},
save() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
this.temp.roles = this.selectRoles.join(',')
this.$request({
url: 'user/save',
method: 'post',
params: this.temp
}).then((response) => {
this.dialogVisible = false
this.$notify({
title: '成功',
message: (this.dialogStatus === 'create' ? '创建' : '修改') + '成功',
type: 'success',
duration: 2000
})
this.$emit('reload-table')
})
}
})
},
getInfo(row) {
for (var t in this.temp) {
if (t !== 'roles') {
this.temp[t] = row[t]
}
}
this.$get('user/roles', { userId: this.temp.id }).then((response) => {
const { data } = response
this.selectRoles = data
})
}
}
}
</script>
@@ -0,0 +1,153 @@
<template>
<div class="app-container">
<div class="filter-container">
<el-form :inline="true">
<el-form-item label="登录名称">
<el-input v-model="tableOptions.where.username" placeholder="登录名称" style="width: 200px;" class="filter-item" />
</el-form-item>
<el-form-item label="姓名/昵称">
<el-input v-model="tableOptions.where.name" placeholder="姓名/昵称" style="width: 200px;" class="filter-item" />
</el-form-item>
<el-button class="filter-item" type="primary" icon="el-icon-search" @click="reloadTable">
搜索
</el-button>
<el-button v-permission="'user:save'" class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">
添加
</el-button>
<el-button :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-download" @click="handleDownload">
导出
</el-button>
</el-form>
</div>
<hr>
<el-row style="margin-bottom: 6px">
<pd-button plain :request-url="'user/delete'" :btn-type="'delete'" :request-data="{ id: ids }" :after-handler="reloadTable" />
</el-row>
<hr>
<pd-table ref="table" v-bind="tableOptions" @selection-change="selectionChange" />
<pd-dialog :visible.sync="dialogFormVisible" @confirm-click="$refs.userForm.save()">
<template #content>
<user-form ref="userForm" :visible.sync="dialogFormVisible" :dialog-status="dialogStatus" @reload-table="reloadTable" />
</template>
</pd-dialog>
</div>
</template>
<script>
import UserForm from './user-form.vue'
export default {
name: 'UserList',
components: { UserForm },
data() {
return {
tableOptions: {
url: 'user/list',
page: true,
selection: true,
where: {
username: '',
name: ''
},
cols: [
{
field: 'username',
title: '登录名称',
sortable: 'custom'
},
{
field: 'name',
title: '姓名/昵称',
sortable: 'custom'
},
{
field: 'phone',
title: '手机号',
width: 200,
sortable: 'custom'
},
{
field: 'isLogin',
title: '禁止登录',
type: 'switch',
width: 200,
change: (row) => {
this.$get('/user/change/login/status', {
id: row.id,
isLogin: row.isLogin
})
}
},
{
field: 'createDate',
title: '创建时间'
},
{
title: '操作',
type: 'btns',
width: 200,
fixed: 'right',
btns: [
{
permission: 'user:save',
title: '修改',
type: 'primary',
click: (row) => {
this.handleUpdate(row)
}
},
{
permission: 'user:delete',
title: '删除',
type: 'danger',
click: (row) => {
this.$common.handleDelete({
url: 'user/delete',
id: row.id,
done: () => this.reloadTable()
})
}
}
]
}
]
},
dialogFormVisible: false,
dialogStatus: '',
downloadLoading: false,
ids: []
}
},
methods: {
selectionChange(columns) {
this.ids = columns.map(it => it['id']).join(',')
},
reloadTable() {
this.$refs.table.reloadList()
},
handleCreate() {
this.dialogStatus = 'create'
this.dialogFormVisible = true
},
handleUpdate(row) {
this.dialogStatus = 'update'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['userForm'].getInfo(row)
})
},
handleDownload() {
this.$common.exportExcel({
url: this.tableOptions.url,
headers: ['登录名称', '姓名'],
columns: ['username', 'name'],
where: this.tableOptions.where
})
}
}
}
</script>