|
@@ -0,0 +1,240 @@
|
|
|
+<template>
|
|
|
+ <div class="adminLogin_box">
|
|
|
+ <div class="top_box">
|
|
|
+ <a-button type="primary" @click="onEditorHandle('add')">新增</a-button>
|
|
|
+ </div>
|
|
|
+ <div class="table_box">
|
|
|
+ <a-table :dataSource="dataSource" :columns="columns" bordered :pagination="false">
|
|
|
+ <template #bodyCell="{ column, text, index, record }">
|
|
|
+ <template v-if="column.dataIndex === 'index'">
|
|
|
+ <div>{{ index + 1 }}</div>
|
|
|
+ </template>
|
|
|
+ <template v-if="column.dataIndex === 'operation'">
|
|
|
+ <div>
|
|
|
+ <span style="margin-right: 10px;">
|
|
|
+ <a-button type="primary" size="small" @click="onEditorHandle('edit', record)">编辑</a-button>
|
|
|
+ </span>
|
|
|
+ <span style="margin-right: 10px;">
|
|
|
+ <a-button size="small" @click="onEditorHandle('edit-pwd', record)">重置密码</a-button>
|
|
|
+ </span>
|
|
|
+ <span>
|
|
|
+ <a-popconfirm title="确定删除该用户?" @confirm="onDeleteHandle(record)">
|
|
|
+ <a-button type="primary" danger size="small">删除</a-button>
|
|
|
+ </a-popconfirm>
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </a-table>
|
|
|
+ <div class="pagination">
|
|
|
+ <a-pagination v-model:current="PageParam['pageNo']" :pageSize="PageParam['pageSize']" :total="PageParam['total']" show-quick-jumper @change="onPaginationHandle" />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <a-modal v-model:open="open" :title="modalType === 'add' ? '新增账户' : '编辑账户'" @ok="onSubmitHandle" >
|
|
|
+ <a-form
|
|
|
+ ref="formRef"
|
|
|
+ :model="formData"
|
|
|
+ :rules="rules"
|
|
|
+ :label-col="{ span: 4 }"
|
|
|
+ :wrapper-col="{ span: 20 }"
|
|
|
+ autocomplete="off"
|
|
|
+ >
|
|
|
+ <a-form-item
|
|
|
+ label="昵称"
|
|
|
+ v-if="['add', 'edit'].includes(modalType)"
|
|
|
+ name="nickname"
|
|
|
+ >
|
|
|
+ <a-input v-model:value="formData.nickname" />
|
|
|
+ </a-form-item>
|
|
|
+
|
|
|
+ <a-form-item
|
|
|
+ label="账号"
|
|
|
+ v-if="['add', 'edit'].includes(modalType)"
|
|
|
+ name="username"
|
|
|
+ >
|
|
|
+ <a-input v-model:value="formData.username" />
|
|
|
+ </a-form-item>
|
|
|
+
|
|
|
+ <a-form-item
|
|
|
+ label="密码"
|
|
|
+ v-if="['add', 'edit-pwd'].includes(modalType)"
|
|
|
+ name="password"
|
|
|
+ >
|
|
|
+ <a-input-password v-model:value="formData.password" />
|
|
|
+ </a-form-item>
|
|
|
+ </a-form>
|
|
|
+ </a-modal>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import axios from "axios";
|
|
|
+import { message } from "ant-design-vue";
|
|
|
+
|
|
|
+defineOptions({
|
|
|
+ name: 'UserManagement'
|
|
|
+})
|
|
|
+const columns = ref([
|
|
|
+ {
|
|
|
+ title: '序号',
|
|
|
+ dataIndex: 'index',
|
|
|
+ key: 'index',
|
|
|
+ width: 100,
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '账号',
|
|
|
+ dataIndex: 'username',
|
|
|
+ key: 'username',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '用户昵称',
|
|
|
+ dataIndex: 'nickname',
|
|
|
+ key: 'nickname',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ dataIndex: 'operation',
|
|
|
+ width: '280px'
|
|
|
+ },
|
|
|
+])
|
|
|
+
|
|
|
+const dataSource = ref([]);
|
|
|
+const PageParam = ref({
|
|
|
+ pageNo: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ total: 0
|
|
|
+})
|
|
|
+
|
|
|
+const queryTableByPage = () => {
|
|
|
+ const urlStr = "/baseApi/system/user/page"
|
|
|
+ const sendData = {
|
|
|
+ ...PageParam.value
|
|
|
+ }
|
|
|
+ axios.get(urlStr, sendData).then((result) => {
|
|
|
+ const resultData = result.data.data;
|
|
|
+ if (resultData) {
|
|
|
+ dataSource.value = resultData.list
|
|
|
+ PageParam.value.pageNo = resultData.total
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+queryTableByPage()
|
|
|
+
|
|
|
+const onPaginationHandle = (page) => {
|
|
|
+ PageParam.value.pageNo = page
|
|
|
+ queryTableByPage()
|
|
|
+}
|
|
|
+/**
|
|
|
+ * 新增、编辑、删除
|
|
|
+ * */
|
|
|
+const formRef = ref(null)
|
|
|
+const modalType = ref('add');
|
|
|
+const open = ref(false)
|
|
|
+const onEditorHandle = (type, item)=>{
|
|
|
+ modalType.value = type
|
|
|
+ open.value = true
|
|
|
+ formData.value = {
|
|
|
+ id: '',
|
|
|
+ nickname: '',
|
|
|
+ username: '',
|
|
|
+ password: ''
|
|
|
+ }
|
|
|
+ if(item){
|
|
|
+ formData.value = {
|
|
|
+ id: item['id'],
|
|
|
+ nickname: item['nickname'],
|
|
|
+ username: item['username'],
|
|
|
+ password: item['password']
|
|
|
+ };
|
|
|
+ }
|
|
|
+}
|
|
|
+const rules = {
|
|
|
+ nickname: [{ required: true, message: '昵称不能为空!' }],
|
|
|
+ username: [{ required: true, message: '账号不能为空!' }],
|
|
|
+ password: [{ required: true, message: '密码不能为空!' }]
|
|
|
+}
|
|
|
+const formData = ref({
|
|
|
+ id: '',
|
|
|
+ nickname: '',
|
|
|
+ username: '',
|
|
|
+ password: ''
|
|
|
+})
|
|
|
+const onSubmitHandle = ()=>{
|
|
|
+ formRef.value
|
|
|
+ .validate()
|
|
|
+ .then(() => {
|
|
|
+ if(modalType.value === 'edit-pwd'){
|
|
|
+ onUpdatePwdHandle();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const sendData = {
|
|
|
+ ...formData.value
|
|
|
+ }
|
|
|
+ const urlStr = modalType.value === 'add' ? '/baseApi/system/user/create' : '/baseApi/system/user/update'
|
|
|
+ axios.post(urlStr, sendData).then((result) => {
|
|
|
+ const resultData = result.data;
|
|
|
+ if(resultData.data){
|
|
|
+ message.success("提交成功")
|
|
|
+ open.value = false
|
|
|
+ onPaginationHandle()
|
|
|
+ }
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ console.log('error', error);
|
|
|
+ });
|
|
|
+}
|
|
|
+const onUpdatePwdHandle = ()=>{
|
|
|
+ formRef.value
|
|
|
+ .validate()
|
|
|
+ .then(() => {
|
|
|
+ const sendData = {
|
|
|
+ ...formData.value
|
|
|
+ }
|
|
|
+ const urlStr = '/baseApi/system/user/update-password'
|
|
|
+ axios.post(urlStr, sendData).then((result) => {
|
|
|
+ const resultData = result.data;
|
|
|
+ if(resultData.data){
|
|
|
+ message.success("密码重置成功")
|
|
|
+ onPaginationHandle(1)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ console.log('error', error);
|
|
|
+ });
|
|
|
+}
|
|
|
+const onDeleteHandle = (item) => {
|
|
|
+ const urlStr = `/baseApi/system/user/delete?id=${item['id']}`
|
|
|
+ axios.get(urlStr).then((result) => {
|
|
|
+ const resultData = result.data;
|
|
|
+ if(resultData.data){
|
|
|
+ message.success("删除成功")
|
|
|
+ onPaginationHandle(1)
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+.adminLogin_box {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ background: #fff;
|
|
|
+ position: relative;
|
|
|
+ padding: 20px;
|
|
|
+ >.top_box {
|
|
|
+ margin-bottom: 10px;
|
|
|
+ }
|
|
|
+ >.table_box {
|
|
|
+ height: calc(100% - 60px);
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ >.pagination {
|
|
|
+ margin-top: 20px;
|
|
|
+ text-align: right;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|