|
@@ -0,0 +1,175 @@
|
|
|
|
+<!-- 用户 -->
|
|
|
|
+<template>
|
|
|
|
+ <el-form :inline="true">
|
|
|
|
+ <el-form-item label="用户名称">
|
|
|
|
+ <el-input v-model="pages.keyword" placeholder="输入用户关键词" clearable />
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item>
|
|
|
|
+ <el-button type="primary" @click="onSubmit">搜索</el-button>
|
|
|
|
+ <el-button type="primary" link @click="() => creatEditPlan()">创建用户</el-button>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ </el-form>
|
|
|
|
+
|
|
|
|
+ <el-table :data="tableData" stripe style="width: 100%">
|
|
|
|
+ <el-table-column prop="userName" label="昵称" />
|
|
|
|
+ <el-table-column prop="phone" label="联系电话" />
|
|
|
|
+
|
|
|
|
+ <el-table-column label="操作">
|
|
|
|
+ <template #default="scope">
|
|
|
|
+ <el-popconfirm
|
|
|
|
+ @confirm="() => deleteAdvertiserFunc(scope.row.uid)"
|
|
|
|
+ title="确定删除该用户吗?"
|
|
|
|
+ >
|
|
|
|
+ <template #reference>
|
|
|
|
+ <el-button link type="primary" size="small">删除</el-button>
|
|
|
|
+ </template>
|
|
|
|
+ </el-popconfirm>
|
|
|
|
+ <el-button link type="primary" size="small" @click="() => creatEditPlan(scope.row)">
|
|
|
|
+ 修改
|
|
|
|
+ </el-button>
|
|
|
|
+ </template>
|
|
|
|
+ </el-table-column>
|
|
|
|
+ </el-table>
|
|
|
|
+ <br />
|
|
|
|
+ <el-pagination
|
|
|
|
+ background
|
|
|
|
+ layout="prev, pager, next"
|
|
|
|
+ :total="pages.total"
|
|
|
|
+ @current-change="page"
|
|
|
|
+ />
|
|
|
|
+
|
|
|
|
+ <el-dialog v-model="dialogVisible" title="用户">
|
|
|
|
+ <el-form :rules="rules" ref="ruleFormRef" :model="form" label-width="auto">
|
|
|
|
+ <el-form-item label="用户名称" prop="userName">
|
|
|
|
+ <el-input v-model="form.userName" />
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="手机号" prop="phone">
|
|
|
|
+ <el-input v-model="form.phone" />
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="角色" prop="roleId">
|
|
|
|
+ <el-select v-model="form.roleId" placeholder="请选择角色" style="width: 240px">
|
|
|
|
+ <el-option
|
|
|
|
+ v-for="item in role"
|
|
|
|
+ :key="item.roleId"
|
|
|
|
+ :label="item.roleName"
|
|
|
|
+ :value="item.roleId"
|
|
|
|
+ />
|
|
|
|
+ </el-select>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item>
|
|
|
|
+ <el-button type="primary" @click="createOrUpdate(ruleFormRef)">确定</el-button>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ </el-form>
|
|
|
|
+ </el-dialog>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<script setup lang="ts">
|
|
|
|
+import type { Pages } from '@/types/Tool'
|
|
|
|
+import type { UserData } from '@/types/User'
|
|
|
|
+import type { FormInstance } from 'element-plus'
|
|
|
|
+import type { Role } from '@/types/Role'
|
|
|
|
+import { getUserList, deleteUser, updateUser, createUser, getRole } from '@/api/index'
|
|
|
|
+import { ref } from 'vue'
|
|
|
|
+// import { statusList } from '@/tool'
|
|
|
|
+import { ElMessage } from 'element-plus'
|
|
|
|
+const pages = ref<Pages>({
|
|
|
|
+ pageNum: 1,
|
|
|
|
+ pageSize: 10,
|
|
|
|
+ total: 0,
|
|
|
|
+})
|
|
|
|
+const dialogVisible = ref(false)
|
|
|
|
+const form = ref<UserData>({
|
|
|
|
+ userName: '',
|
|
|
|
+ phone: '',
|
|
|
|
+})
|
|
|
|
+const ruleFormRef = ref<FormInstance>()
|
|
|
|
+
|
|
|
|
+const tableData = ref<UserData[]>()
|
|
|
|
+const role = ref<Role[]>()
|
|
|
|
+
|
|
|
|
+getRole().then(({ data }) => {
|
|
|
|
+ role.value = data
|
|
|
|
+ console.log(data)
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+const rules = {
|
|
|
|
+ phone: [
|
|
|
|
+ {
|
|
|
|
+ required: true,
|
|
|
|
+ message: '请输入手机号',
|
|
|
|
+ trigger: 'blur',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ pattern: /^1[3456789]\d{9}$/,
|
|
|
|
+ message: '请输入正确的手机号',
|
|
|
|
+ trigger: 'blur',
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ userName: [
|
|
|
|
+ {
|
|
|
|
+ required: true,
|
|
|
|
+ message: '请输入用户名',
|
|
|
|
+ trigger: 'blur',
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ roleId: [
|
|
|
|
+ {
|
|
|
|
+ required: true,
|
|
|
|
+ message: '请选择角色',
|
|
|
|
+ trigger: 'change',
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const onSubmit = () => {
|
|
|
|
+ getUserList(pages.value).then(({ data }) => {
|
|
|
|
+ tableData.value = data.records
|
|
|
|
+ pages.value.total = data.total
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const page = (val: number) => {
|
|
|
|
+ pages.value.pageNum = val
|
|
|
|
+ onSubmit()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const creatEditPlan = (data?: UserData) => {
|
|
|
|
+ if (data != undefined) form.value = data
|
|
|
|
+ else
|
|
|
|
+ form.value = {
|
|
|
|
+ userName: '',
|
|
|
|
+ phone: '',
|
|
|
|
+ }
|
|
|
|
+ dialogVisible.value = !dialogVisible.value
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const deleteAdvertiserFunc = (id: number) =>
|
|
|
|
+ deleteUser(id).then(() => {
|
|
|
|
+ ElMessage.success('删除成功')
|
|
|
|
+ onSubmit()
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+const createOrUpdate = (formEl: FormInstance | undefined) => {
|
|
|
|
+ if (!formEl) return
|
|
|
|
+ formEl.validate((valid) => {
|
|
|
|
+ console.log(valid)
|
|
|
|
+ if (!valid) return
|
|
|
|
+ const Func = form.value.uid == undefined ? createUser : updateUser
|
|
|
|
+ const p = {
|
|
|
|
+ userName: form.value.userName,
|
|
|
|
+ phone: form.value.phone,
|
|
|
|
+ roleId: form.value.roleId,
|
|
|
|
+ uid: form.value.uid,
|
|
|
|
+ }
|
|
|
|
+ Func(p).then(() => {
|
|
|
|
+ ElMessage.success(p.uid == undefined ? '更新成功' : '修改成功')
|
|
|
|
+ onSubmit()
|
|
|
|
+ dialogVisible.value = false
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+onSubmit()
|
|
|
|
+</script>
|
|
|
|
+
|
|
|
|
+<style></style>
|