|
@@ -1,126 +1,192 @@
|
|
|
<script setup lang="ts">
|
|
|
+import { ref, reactive, nextTick } from 'vue'
|
|
|
import TableBase from '@/components/TableBase/index.vue'
|
|
|
-import { ColumnProps } from '@/components/TableBase/interface/index'
|
|
|
-import { Edit, Delete } from '@element-plus/icons-vue'
|
|
|
+import type { ColumnProps } from '@/components/TableBase/interface/index'
|
|
|
+import { User_Power_List, User_Sys_List, Menu_List, User_Power_Add, User_Power_Del } from '@/api/role/index'
|
|
|
+import { Edit, Delete, Operation } from '@element-plus/icons-vue'
|
|
|
+import Dialog from '@/components/dialog/Dialog.vue'
|
|
|
import Drawer from '@/components/Drawer/index.vue'
|
|
|
-import { ref, reactive } from 'vue'
|
|
|
-const drawerRef = ref()
|
|
|
-const action = ref(true)
|
|
|
-const formLabelWidth = ref('80px')
|
|
|
-const form = reactive({
|
|
|
- username: '',
|
|
|
- password: '',
|
|
|
- user: '',
|
|
|
- department: '',
|
|
|
- post: ''
|
|
|
-})
|
|
|
+import { GlobalStore } from '@/stores/index'
|
|
|
+import type { FormInstance, FormRules } from 'element-plus'
|
|
|
+import { ElNotification, ElMessageBox, ElMessage } from 'element-plus'
|
|
|
+
|
|
|
+const globalStore = GlobalStore()
|
|
|
+const dialog = ref()
|
|
|
+const TableRef = ref()
|
|
|
+const DialogOpen = async (row: any) => {
|
|
|
+ console.log(row)
|
|
|
+ await getSysList()
|
|
|
+ dialog.value.DialogOpen()
|
|
|
+}
|
|
|
+const checkList = ref()
|
|
|
const columns: ColumnProps[] = [
|
|
|
{ type: 'index', label: '#', width: 80 },
|
|
|
- { prop: 'date', label: '时间', width: 120, search: { el: 'input' } },
|
|
|
- {
|
|
|
- prop: 'name',
|
|
|
- label: '姓名',
|
|
|
- width: 120,
|
|
|
- sortable: true,
|
|
|
- // enum: getUserGender,
|
|
|
- search: { el: 'select' },
|
|
|
- fieldNames: { label: 'genderLabel', value: 'genderValue' }
|
|
|
- },
|
|
|
- { prop: 'address', label: '身份证号' },
|
|
|
- { prop: 'email', label: '邮箱' },
|
|
|
- { prop: 'address', label: '居住地址' },
|
|
|
- {
|
|
|
- prop: 'status',
|
|
|
- label: '用户状态',
|
|
|
- width: 120,
|
|
|
- sortable: true,
|
|
|
- tag: true,
|
|
|
- // enum: getUserStatus,
|
|
|
- search: { el: 'select' },
|
|
|
- fieldNames: { label: 'userLabel', value: 'userStatus' }
|
|
|
- },
|
|
|
- { prop: 'createTime', label: '创建时间', width: 180 },
|
|
|
+ { prop: 'T_name', label: '姓名' },
|
|
|
+ { prop: 'T_id', label: 'id' },
|
|
|
{ prop: 'operation', label: '操作', width: 200, fixed: 'right' }
|
|
|
]
|
|
|
-const requestApi = async () => {
|
|
|
- return false
|
|
|
+
|
|
|
+interface InSys {
|
|
|
+ T_sys: string
|
|
|
+ T_name: string
|
|
|
+ children: any
|
|
|
}
|
|
|
|
|
|
-const openDrawer = () => {
|
|
|
- drawerRef.value.closeDrawer()
|
|
|
- console.log(drawerRef.value)
|
|
|
+let SysList = ref<InSys[]>([])
|
|
|
+const getSysList = async () => {
|
|
|
+ const { Data } = await User_Sys_List({ User_tokey: globalStore.GET_User_tokey })
|
|
|
+ SysList.value = Data as InSys[]
|
|
|
+}
|
|
|
+// let MenuList = reactive([])
|
|
|
+const getMenuList = async (code: string) => {
|
|
|
+ const res = await Menu_List({ User_tokey: globalStore.GET_User_tokey, T_code: code })
|
|
|
+ const sys = SysList.value.find(item => item.T_sys === code) as InSys
|
|
|
+ console.log(SysList, sys, res)
|
|
|
+ sys.children = res.Data.Data[0].Children
|
|
|
+}
|
|
|
+const submitUserRole = () => {
|
|
|
+ console.log(checkList)
|
|
|
+}
|
|
|
+const initParam = {
|
|
|
+ User_tokey: globalStore.GET_User_tokey,
|
|
|
+ page: 1,
|
|
|
+ page_z: 10
|
|
|
}
|
|
|
|
|
|
+// 添加角色
|
|
|
+const drawerRef = ref()
|
|
|
+const ruleFormRef = ref<FormInstance>()
|
|
|
+const formLabelWidth = ref('80px')
|
|
|
+const isNew = ref(true)
|
|
|
+const rules = reactive<FormRules>({
|
|
|
+ name: [{ required: true, message: '请输入角色名称', trigger: 'blur' }]
|
|
|
+})
|
|
|
type Fn = () => void
|
|
|
const callbackDrawer = (done: Fn) => {
|
|
|
- console.log('触发回调')
|
|
|
+ resetForm(ruleFormRef.value)
|
|
|
done()
|
|
|
}
|
|
|
+const openDrawer = (type: string, row?: any) => {
|
|
|
+ isNew.value = type === 'new' ? true : false
|
|
|
+ nextTick(() => {
|
|
|
+ !isNew.value && (form.name = row.T_name)
|
|
|
+ })
|
|
|
+ drawerRef.value.closeDrawer()
|
|
|
+}
|
|
|
+const form = reactive({
|
|
|
+ name: ''
|
|
|
+})
|
|
|
+const resetForm = (formEl: FormInstance | undefined) => {
|
|
|
+ if (!formEl) return
|
|
|
+ formEl.resetFields()
|
|
|
+}
|
|
|
+const AddUserName = (formEl: FormInstance | undefined) => {
|
|
|
+ if (!formEl) return
|
|
|
+ formEl.validate(async valid => {
|
|
|
+ if (valid) {
|
|
|
+ let res = await User_Power_Add({ User_tokey: globalStore.GET_User_tokey, T_name: form.name })
|
|
|
+ if (res.Code === 200) {
|
|
|
+ ElNotification.success({
|
|
|
+ title: '添加角色',
|
|
|
+ message: '添加成功!',
|
|
|
+ position: 'bottom-right'
|
|
|
+ })
|
|
|
+ drawerRef.value.closeDrawer()
|
|
|
+ TableRef.value.getTableList()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.log('error submit!')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 删除
|
|
|
+const UserDelete = (row: any) => {
|
|
|
+ ElMessageBox.confirm('您确定要删除吗?', '警告', {
|
|
|
+ confirmButtonText: 'OK',
|
|
|
+ cancelButtonText: 'Cancel',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ .then(async () => {
|
|
|
+ const res = await User_Power_Del({ User_tokey: globalStore.GET_User_tokey, T_id: row.T_id })
|
|
|
+ console.log(res)
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ ElMessage({
|
|
|
+ type: 'warning',
|
|
|
+ message: '取消成功!'
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
- <TableBase :columns="columns" :requestApi="requestApi">
|
|
|
+ <TableBase ref="TableRef" :columns="columns" :requestApi="User_Power_List" :initParam="initParam">
|
|
|
<template #table-header>
|
|
|
<div class="input-suffix">
|
|
|
<el-row :gutter="20">
|
|
|
<el-col :span="12">
|
|
|
- <span class="ml-3 w-35 text-gray-600 inline-flex items-center">账户查询:</span>
|
|
|
+ <span class="ml-3 w-35 text-gray-600 inline-flex items-center">角色名:</span>
|
|
|
<el-input type="text" class="w-50 m-2" />
|
|
|
<el-button type="primary">搜索</el-button>
|
|
|
</el-col>
|
|
|
- <el-col :span="6" :offset="6"><el-button type="primary" @click="openDrawer">添加</el-button></el-col>
|
|
|
+ <el-col :span="6" :offset="6"><el-button type="primary" @click="openDrawer('new')">添加</el-button></el-col>
|
|
|
</el-row>
|
|
|
</div>
|
|
|
</template>
|
|
|
- <template #right>
|
|
|
- <el-button link type="primary" size="small" :icon="Edit">编辑</el-button>
|
|
|
- <el-button link type="danger" size="small" :icon="Delete">删除</el-button>
|
|
|
+ <template #right="{ row }">
|
|
|
+ <el-button link type="primary" size="small" :icon="Edit" @click="openDrawer('edit', row)">编辑</el-button>
|
|
|
+ <el-button link type="success" size="small" :icon="Operation" @click="DialogOpen(row)">权限</el-button>
|
|
|
+ <el-button link type="danger" size="small" :icon="Delete" @click="UserDelete(row)">删除</el-button>
|
|
|
</template>
|
|
|
</TableBase>
|
|
|
+ <Dialog ref="dialog" width="80%">
|
|
|
+ <template #header>
|
|
|
+ <h3>编辑权限</h3>
|
|
|
+ </template>
|
|
|
+ <el-row :gutter="24">
|
|
|
+ <el-col :span="3"><div class="grid-content">功能模块</div></el-col>
|
|
|
+ <el-col :span="18"><div class="grid-content">权限</div></el-col>
|
|
|
+ <el-col :span="3"><div class="grid-content">操作</div></el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-row :gutter="24" v-for="item in SysList" :key="item.T_sys">
|
|
|
+ <el-col :span="3"
|
|
|
+ ><div class="grid-content">
|
|
|
+ <el-button type="success" link @click="getMenuList(item.T_sys)">{{ item.T_name }}</el-button>
|
|
|
+ </div></el-col
|
|
|
+ >
|
|
|
+ <el-col :span="18"
|
|
|
+ ><div class="grid-content grid-active">
|
|
|
+ <el-checkbox-group v-model="checkList" v-if="item.children">
|
|
|
+ <el-checkbox :label="child.T_name" v-for="child in item.children" :key="'rr' + child.Id">{{
|
|
|
+ child.T_name
|
|
|
+ }}</el-checkbox>
|
|
|
+ </el-checkbox-group>
|
|
|
+ </div></el-col
|
|
|
+ >
|
|
|
+ <el-col :span="3"
|
|
|
+ ><div class="grid-content">
|
|
|
+ <el-button type="primary" @click="submitUserRole">提交</el-button>
|
|
|
+ </div></el-col
|
|
|
+ >
|
|
|
+ </el-row>
|
|
|
+ </Dialog>
|
|
|
<Drawer ref="drawerRef" :handleClose="callbackDrawer">
|
|
|
<template #header="{ params }">
|
|
|
- <h4 :id="params.titleId" :class="params.titleClass">{{ action ? '添加' : '编辑' }} - 账户管理</h4>
|
|
|
+ <h4 :id="params.titleId" :class="params.titleClass">{{ isNew ? '添加' : '编辑' }} - 角色</h4>
|
|
|
</template>
|
|
|
- <el-form :model="form" class="form">
|
|
|
- <el-form-item label="用户名:" :label-width="formLabelWidth">
|
|
|
- <el-input v-model="form.username" autocomplete="off" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="密码:" :label-width="formLabelWidth">
|
|
|
- <el-input v-model="form.username" autocomplete="off" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="角色名:" :label-width="formLabelWidth">
|
|
|
- <el-select v-model="form.password" placeholder="请选择角色">
|
|
|
- <el-option label="Area1" value="shanghai" />
|
|
|
- <el-option label="Area2" value="beijing" />
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="部门:" :label-width="formLabelWidth">
|
|
|
- <el-select v-model="form.password" placeholder="请选择部门">
|
|
|
- <el-option label="Area1" value="shanghai" />
|
|
|
- <el-option label="Area2" value="beijing" />
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="岗位:" :label-width="formLabelWidth">
|
|
|
- <el-select v-model="form.password" placeholder="请选择岗位">
|
|
|
- <el-option label="Area1" value="shanghai" />
|
|
|
- <el-option label="Area2" value="beijing" />
|
|
|
- </el-select>
|
|
|
+ <el-form ref="ruleFormRef" :model="form" :rules="rules">
|
|
|
+ <el-form-item label="角色名:" :label-width="formLabelWidth" prop="name">
|
|
|
+ <el-input v-model="form.name" type="text" autocomplete="off" placeholder="请输入角色名称" />
|
|
|
</el-form-item>
|
|
|
<el-form-item :label-width="formLabelWidth">
|
|
|
- <el-button color="#626aef">添加</el-button>
|
|
|
+ <el-button color="#626aef" @click="AddUserName(ruleFormRef)">添加</el-button>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
</Drawer>
|
|
|
</template>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
-.input-suffix {
|
|
|
- width: 100%;
|
|
|
- .w-50 {
|
|
|
- width: 12.5rem;
|
|
|
- }
|
|
|
-}
|
|
|
-.form {
|
|
|
- margin-top: 3rem;
|
|
|
-}
|
|
|
+@import './index.scss';
|
|
|
</style>
|