Procházet zdrojové kódy

修改用户管理

zs před 1 rokem
rodič
revize
45b1ec5a5a

+ 1 - 0
src/lang/package/zh-cn/common.js

@@ -8,6 +8,7 @@ export default {
   dict: '字典数据',
   sign: '报名管理',
   delete_confirm: '您确定删除该数据?',
+  statusMessage: '请选择审核状态',
   search: '查询',
   reset: '重置',
   view: '查看',

+ 11 - 0
src/lang/package/zh-cn/pages.js

@@ -52,6 +52,17 @@ export default {
     changeToDisabled: '您确定要禁用该用户?',
     password: '密码'
   },
+  user: {
+    dialogTitle: '用户信息',
+    examDialogTitle: '用户审核',
+    account: '账号',
+    password: '密码',
+    nick_name: '昵称',
+    gender: '性别',
+    phone: '手机号',
+    role: '角色',
+    status: '状态'
+  },
   dict: {
     addDialogTitle: '新增字典类型',
     upDialogTitle: '修改字典类型',

+ 40 - 0
src/store/api/user/user.js

@@ -0,0 +1,40 @@
+import { defineStore } from 'pinia'
+import { AxiosWrapper } from '@/utils/axios-wrapper'
+import { get } from 'lodash-es'
+const url = '/user'
+const axios = new AxiosWrapper()
+
+export const UserStore = defineStore('users', () => {
+  const query = async ({ skip = 0, limit = undefined, ...info } = {}) => {
+    let cond = {}
+    if (skip) cond.skip = skip
+    if (limit) cond.limit = limit
+    cond = { ...cond, ...info }
+    const res = await axios.$get(`${url}`, cond)
+    return res
+  }
+  const fetch = async (payload) => {
+    const res = await axios.$get(`${url}/${payload}`)
+    return res
+  }
+  const create = async (payload) => {
+    const res = await axios.$post(`${url}`, payload)
+    return res
+  }
+  const update = async (payload) => {
+    const id = get(payload, 'id', get(payload, '_id'))
+    const res = await axios.$post(`${url}/${id}`, payload)
+    return res
+  }
+  const del = async (payload) => {
+    const res = await axios.$delete(`${url}/${payload}`)
+    return res
+  }
+  return {
+    query,
+    fetch,
+    create,
+    update,
+    del
+  }
+})

+ 2 - 2
src/views/achievement/index.vue

@@ -93,7 +93,7 @@ const opera = [
 const buttonFields = [{ label: t('common.add'), method: 'add' }]
 let skip = 0
 let limit = inject('limit')
-const total = ref(20)
+const total = ref(0)
 // 字典表
 const isUseList = ref([])
 const statusList = ref([])
@@ -126,7 +126,7 @@ const dialog = ref({ type: '1', show: false, title: t('pages.achievement.addDial
 const form = ref({})
 // 审核
 const examFormFields = [{ label: t('pages.achievement.status'), model: 'status', type: 'select' }]
-const examRules = reactive({ title: [{ required: true, message: t('pages.achievement.titleMessage'), trigger: 'blur' }] })
+const examRules = reactive({ status: [{ required: true, message: t('common.statusMessage'), trigger: 'blur' }] })
 const examForm = ref({})
 // 请求
 onMounted(async () => {

+ 1 - 1
src/views/match/info/index.vue

@@ -101,7 +101,7 @@ const dialog = ref({ type: '1', show: false, title: t('pages.match.addDialogTitl
 const form = ref({ rules: {} })
 // 审核
 const examFormFields = [{ label: t('pages.match.status'), model: 'status', type: 'select' }]
-const examRules = reactive({ title: [{ required: true, message: t('pages.match.titleMessage'), trigger: 'blur' }] })
+const examRules = reactive({ status: [{ required: true, message: t('common.statusMessage'), trigger: 'blur' }] })
 const examForm = ref({})
 // 赛事规则
 const rulesFields = ref([

+ 1 - 1
src/views/platform/demand/demand/index.vue

@@ -109,7 +109,7 @@ const dialog = ref({ type: '1', show: false, title: t('pages.demand.addDialogTit
 const form = ref({})
 // 审核
 const examFormFields = [{ label: t('pages.demand.status'), model: 'status', type: 'select' }]
-const examRules = reactive({ title: [{ required: true, message: t('pages.demand.titleMessage'), trigger: 'blur' }] })
+const examRules = reactive({ status: [{ required: true, message: t('common.statusMessage'), trigger: 'blur' }] })
 const examForm = ref({})
 // 请求
 onMounted(async () => {

+ 1 - 1
src/views/platform/demand/supply/index.vue

@@ -109,7 +109,7 @@ const dialog = ref({ type: '1', show: false, title: t('pages.demand.addDialogTit
 const form = ref({})
 // 审核
 const examFormFields = [{ label: t('pages.demand.status'), model: 'status', type: 'select' }]
-const examRules = reactive({ title: [{ required: true, message: t('pages.demand.titleMessage'), trigger: 'blur' }] })
+const examRules = reactive({ status: [{ required: true, message: t('common.statusMessage'), trigger: 'blur' }] })
 const examForm = ref({})
 // 请求
 onMounted(async () => {

+ 1 - 1
src/views/platform/news/index.vue

@@ -87,7 +87,7 @@ const dialog = ref({ type: '1', show: false, title: t('pages.news.addDialogTitle
 const form = ref({})
 // 审核
 const examFormFields = [{ label: t('pages.news.status'), model: 'status', type: 'select' }]
-const examRules = reactive({ title: [{ required: true, message: t('pages.news.titleMessage'), trigger: 'blur' }] })
+const examRules = reactive({ status: [{ required: true, message: t('common.statusMessage'), trigger: 'blur' }] })
 const examForm = ref({})
 // 请求
 onMounted(async () => {

+ 1 - 1
src/views/platform/policy/index.vue

@@ -87,7 +87,7 @@ const dialog = ref({ type: '1', show: false, title: t('pages.news.addDialogTitle
 const form = ref({})
 // 审核
 const examFormFields = [{ label: t('pages.news.status'), model: 'status', type: 'select' }]
-const examRules = reactive({ title: [{ required: true, message: t('pages.news.titleMessage'), trigger: 'blur' }] })
+const examRules = reactive({ status: [{ required: true, message: t('common.statusMessage'), trigger: 'blur' }] })
 const examForm = ref({})
 // 请求
 onMounted(async () => {

+ 1 - 1
src/views/user/admin/index.vue

@@ -91,7 +91,7 @@ const searchOther = async () => {
   if ($checkRes(result)) {
     isUseList.value = result.data
   }
-  const roleResult = await roleStore.query()
+  const roleResult = await roleStore.query({ is_use: '0' })
   if ($checkRes(roleResult)) {
     roleList.value = roleResult.data
   }

+ 0 - 20
src/views/user/company/index.vue

@@ -1,20 +0,0 @@
-<template>
-  <div id="index">
-    <el-row>
-      <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
-        <el-col :span="24" class="one"> 企业 </el-col>
-      </el-col>
-    </el-row>
-  </div>
-</template>
-
-<script setup>
-// 加载中
-const loading = ref(false)
-// 请求
-onMounted(async () => {
-  loading.value = true
-  loading.value = false
-})
-</script>
-<style scoped lang="scss"></style>

+ 0 - 20
src/views/user/expert/index.vue

@@ -1,20 +0,0 @@
-<template>
-  <div id="index">
-    <el-row>
-      <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
-        <el-col :span="24" class="one"> 专家 </el-col>
-      </el-col>
-    </el-row>
-  </div>
-</template>
-
-<script setup>
-// 加载中
-const loading = ref(false)
-// 请求
-onMounted(async () => {
-  loading.value = true
-  loading.value = false
-})
-</script>
-<style scoped lang="scss"></style>

+ 0 - 20
src/views/user/unit/index.vue

@@ -1,20 +0,0 @@
-<template>
-  <div id="index">
-    <el-row>
-      <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
-        <el-col :span="24" class="one"> 科研机构 </el-col>
-      </el-col>
-    </el-row>
-  </div>
-</template>
-
-<script setup>
-// 加载中
-const loading = ref(false)
-// 请求
-onMounted(async () => {
-  loading.value = true
-  loading.value = false
-})
-</script>
-<style scoped lang="scss"></style>

+ 138 - 9
src/views/user/user/index.vue

@@ -1,20 +1,149 @@
 <template>
-  <div id="index">
-    <el-row>
-      <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
-        <el-col :span="24" class="one"> 平台用户 </el-col>
-      </el-col>
-    </el-row>
+  <div class="main animate__animated animate__backInRight">
+    <custom-search-bar v-model="searchForm" :fields="fields.filter((f) => f.filter)" @search="search" @reset="toReset"></custom-search-bar>
+    <custom-table :data="data" :fields="fields" @search="search" :total="total" :opera="opera" @exam="toExam" @view="toView" @delete="toDelete"> </custom-table>
+    <el-dialog v-model="dialog.show" :title="dialog.title" :destroy-on-close="false" @close="toClose">
+      <el-row>
+        <el-col :span="24" v-if="dialog.type == '1'">
+          <custom-form v-model="form" :fields="formFields" :useSave="false">
+            <template #gender>
+              <el-option v-for="i in genderList" :key="i._id" :label="i.label" :value="i.value"></el-option>
+            </template>
+            <template #role>
+              {{ getRole(form.role) }}
+            </template>
+          </custom-form>
+        </el-col>
+        <el-col :span="24" v-if="dialog.type == '2'">
+          <custom-form v-model="examForm" :fields="examFormFields" :rules="examRules" @save="toExamSave">
+            <template #status>
+              <el-option v-for="i in statusList" :key="i._id" :label="i.label" :value="i.value"></el-option>
+            </template>
+          </custom-form>
+        </el-col>
+      </el-row>
+    </el-dialog>
   </div>
 </template>
 
 <script setup>
-// 加载中
+import { UserStore } from '@/store/api/user/user'
+import { RoleStore } from '@/store/api/system/role'
+import { DictDataStore } from '@/store/api/system/dictData'
+import { cloneDeep, get } from 'lodash-es'
+const $checkRes = inject('$checkRes')
+const store = UserStore()
+const dictDataStore = DictDataStore()
+const roleStore = RoleStore()
+const { t } = useI18n()
 const loading = ref(false)
-// 请求
+let skip = 0
+let limit = inject('limit')
+const data = ref([])
+const total = ref(0)
 onMounted(async () => {
   loading.value = true
+  await searchOther()
+  await search({ skip, limit })
   loading.value = false
 })
+const fields = [
+  { label: t('pages.user.account'), model: 'account', filter: true },
+  { label: t('pages.user.nick_name'), model: 'nick_name' },
+  { label: t('pages.user.phone'), model: 'phone' },
+  { label: t('pages.user.role'), model: 'role', format: (i) => getRole(i) },
+  { label: t('pages.user.status'), model: 'status', format: (i) => getDict(i) }
+]
+const opera = [
+  { label: t('common.view'), method: 'view' },
+  { label: t('common.exam'), method: 'exam', type: 'warning', display: (i) => i.status === '0' },
+  { label: t('common.delete'), method: 'delete', confirm: true, type: 'danger', display: (i) => i.status === '-1' }
+]
+const searchForm = ref({})
+const dialog = ref({ type: '1', show: false, title: t('pages.user.dialogTitle') })
+// 审核
+const examFormFields = [{ label: t('pages.user.status'), model: 'status', type: 'select' }]
+const examRules = reactive({ status: [{ required: true, message: t('common.statusMessage'), trigger: 'blur' }] })
+const examForm = ref({})
+const search = async (query = { skip: 0, limit }) => {
+  const info = { skip: query.skip, limit: query.limit, ...searchForm.value }
+  const res = await store.query(info)
+  if (res.errcode == '0') {
+    data.value = res.data
+    total.value = res.total
+  }
+}
+const statusList = ref([])
+const roleList = ref([])
+const genderList = ref([])
+const searchOther = async () => {
+  let result
+  // 状态
+  result = await dictDataStore.query({ code: 'examStatus', is_use: '0' })
+  if ($checkRes(result)) statusList.value = result.data
+  // 性别
+  result = await dictDataStore.query({ code: 'gender', is_use: '0' })
+  if ($checkRes(result)) genderList.value = result.data
+  // 角色
+  result = await roleStore.query({ is_use: '0' })
+  if ($checkRes(result)) roleList.value = result.data
+}
+
+const toDelete = async (data) => {
+  const res = await store.del(data._id)
+  if ($checkRes(res, true)) {
+    search({ skip: 0, limit })
+  }
+}
+const form = ref({})
+const formFields = ref([])
+const formFieldsForUpdate = [
+  { label: t('pages.user.account'), model: 'account' },
+  { label: t('pages.user.nick_name'), model: 'nick_name' },
+  { label: t('pages.user.gender'), model: 'gender', type: 'select' },
+  { label: t('pages.user.phone'), model: 'phone' },
+  { label: t('pages.user.role'), model: 'role', custom: true }
+]
+const toView = (data) => {
+  formFields.value = cloneDeep(formFieldsForUpdate)
+  form.value = data
+  dialog.value = { type: '1', show: true, title: t('pages.user.dialogTitle') }
+}
+// 审核
+const toExam = (data) => {
+  examForm.value = data
+  dialog.value = { type: '2', show: true, title: t('pages.user.examDialogTitle') }
+}
+// 审核保存
+const toExamSave = async () => {
+  const data = cloneDeep(examForm.value)
+  let res = await store.update(data)
+  if ($checkRes(res, true)) {
+    search({ skip: 0, limit })
+    toClose()
+  }
+}
+const getRole = (data) => {
+  const list = []
+  for (const val of data) {
+    const res = roleList.value.find((f) => f.code === val)
+    list.push(get(res, 'name'))
+  }
+  return list.join(',')
+}
+const getDict = (data) => {
+  const res = statusList.value.find((f) => f.value == data)
+  return get(res, 'label')
+}
+const toClose = () => {
+  examForm.value = {}
+  form.value = {}
+  dialog.value = { show: false }
+}
+// 重置
+const toReset = async () => {
+  searchForm.value = {}
+  await search({ skip, limit })
+}
 </script>
-<style scoped lang="scss"></style>
+<style scoped></style>