|
@@ -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>
|