|
@@ -0,0 +1,172 @@
|
|
|
+<template>
|
|
|
+ <div id="index">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24" class="main animate__animated animate__backInRight">
|
|
|
+ <el-col :span="24" class="one">
|
|
|
+ <c-search :is_title="false" :is_back="true" @toBack="toBack"> </c-search>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24" class="two">
|
|
|
+ <component :is="search1" :form="searchForm" @onSubmit="toSearch" @toReset="toReset" @changeType="changeType"></component>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24" class="two">
|
|
|
+ <cButton @toAdd="toAdd()"> </cButton>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24" class="fou">
|
|
|
+ <cTable :fields="fields" :opera="opera" :data="list" @query="search" :total="total" @edit="toEdit" @del="toDel" :select="false"> </cTable>
|
|
|
+ </el-col>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <cDialog :dialog="dialog" @handleClose="toClose">
|
|
|
+ <template v-slot:info>
|
|
|
+ <cForm v-if="dialog.type == '1'" :span="24" :fields="formFields" :form="form" :rules="rules" @save="onSubmit">
|
|
|
+ <template #status>
|
|
|
+ <el-radio label="0">正常</el-radio>
|
|
|
+ <el-radio label="1">停用</el-radio>
|
|
|
+ </template>
|
|
|
+ <template #is_default>
|
|
|
+ <el-radio label="0">非默认</el-radio>
|
|
|
+ <el-radio label="1">默认</el-radio>
|
|
|
+ </template>
|
|
|
+ </cForm>
|
|
|
+ </template>
|
|
|
+ </cDialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script lang="ts" setup>
|
|
|
+import _ from 'lodash'
|
|
|
+import search1 from './parts_two/search-1.vue'
|
|
|
+import type { FormRules } from 'element-plus'
|
|
|
+import type { Ref } from 'vue'
|
|
|
+import { ref, onMounted, getCurrentInstance, reactive } from 'vue'
|
|
|
+import { ElMessage } from 'element-plus'
|
|
|
+import { useRoute } from 'vue-router'
|
|
|
+import { DictDataStore } from '@common/src/stores/system/dictData' // 字典表
|
|
|
+import type { IQueryResult } from '@/util/types.util'
|
|
|
+const dictData = DictDataStore()
|
|
|
+const route = useRoute()
|
|
|
+const { proxy } = getCurrentInstance() as any
|
|
|
+// 列表数据
|
|
|
+let list: Ref<any[]> = ref([])
|
|
|
+// 总数
|
|
|
+let total: Ref<number> = ref(0)
|
|
|
+let skip = 0
|
|
|
+let limit: number = proxy.$limit
|
|
|
+// 列表
|
|
|
+let fields: Ref<any[]> = ref([
|
|
|
+ { label: '字典标签', model: 'dict_label' },
|
|
|
+ { label: '字典键值', model: 'dict_value' },
|
|
|
+ { label: '字典排序', model: 'dict_sort' },
|
|
|
+ { label: '状态', model: 'status', format: (i) => (i == '0' ? '正常' : '停用') }
|
|
|
+])
|
|
|
+// 操作
|
|
|
+let opera: Ref<any[]> = ref([
|
|
|
+ { label: '修改', method: 'edit' },
|
|
|
+ { label: '删除', method: 'del', confirm: true, type: 'danger' }
|
|
|
+])
|
|
|
+const dialog: Ref<{ type: string; show: boolean; title: string }> = ref({ type: '1', show: false, title: '信息管理' })
|
|
|
+let form: Ref<any> = ref({})
|
|
|
+
|
|
|
+// 表单
|
|
|
+let formFields: Ref<any[]> = ref([
|
|
|
+ { label: '字典类型', model: 'dict_type' },
|
|
|
+ { label: '字典标签', model: 'dict_label' },
|
|
|
+ { label: '字典键值', model: 'dict_value' },
|
|
|
+ { label: '显示排序', model: 'dict_sort', type: 'number' },
|
|
|
+ { label: '是否默认', model: 'is_default', type: 'radio' },
|
|
|
+ { label: '状态', model: 'status', type: 'radio' }
|
|
|
+])
|
|
|
+const rules = reactive<FormRules>({
|
|
|
+ dict_name: [{ required: true, message: '请输入字典名称', trigger: 'blur' }],
|
|
|
+ dict_type: [{ required: true, message: '请输入字典类型', trigger: 'blur' }],
|
|
|
+ status: [{ required: true, message: '请选择状态', trigger: 'change' }]
|
|
|
+})
|
|
|
+
|
|
|
+// 查询数据
|
|
|
+let searchForm: Ref<any> = ref({})
|
|
|
+let dict_type: Ref<any> = ref('')
|
|
|
+
|
|
|
+onMounted(async () => {
|
|
|
+ await searchOther()
|
|
|
+ await search({ skip, limit })
|
|
|
+})
|
|
|
+// 查询
|
|
|
+const search = async (e: { skip: number; limit: number }) => {
|
|
|
+ const { skip, limit } = e
|
|
|
+ const condition = _.cloneDeep(searchForm.value)
|
|
|
+ let info = { limit: limit, skip: skip, ...condition }
|
|
|
+ let res: IQueryResult = await dictData.query(info)
|
|
|
+ if (res.errcode == 0) {
|
|
|
+ list.value = res.data as any[]
|
|
|
+ total.value = res.total
|
|
|
+ }
|
|
|
+}
|
|
|
+const toSearch = () => {
|
|
|
+ search({ skip, limit })
|
|
|
+}
|
|
|
+const searchOther = () => {
|
|
|
+ if (route.query.dict_type) dict_type.value = route.query.dict_type
|
|
|
+ form.value.dict_type = dict_type.value
|
|
|
+ searchForm.value.dict_type = dict_type.value
|
|
|
+ console.log(searchForm.value)
|
|
|
+}
|
|
|
+const toReset = () => {
|
|
|
+ searchForm.value = { dict_type: route.query.dict_type }
|
|
|
+ search({ skip, limit })
|
|
|
+}
|
|
|
+// 新增
|
|
|
+const toAdd = () => {
|
|
|
+ dialog.value = { title: '信息管理', show: true, type: '1' }
|
|
|
+}
|
|
|
+// 修改
|
|
|
+const toEdit = async (data) => {
|
|
|
+ let res: IQueryResult = await dictData.fetch(data._id)
|
|
|
+ if (res.errcode == 0) {
|
|
|
+ form.value = res.data as {}
|
|
|
+ dialog.value = { title: '信息管理', show: true, type: '1' }
|
|
|
+ }
|
|
|
+}
|
|
|
+// 提交
|
|
|
+const onSubmit = async (data) => {
|
|
|
+ let res: IQueryResult
|
|
|
+ if (data._id) res = await dictData.update(data)
|
|
|
+ else res = await dictData.create(data)
|
|
|
+ if (res.errcode == 0) {
|
|
|
+ ElMessage({ type: `success`, message: `维护信息成功` })
|
|
|
+ toClose()
|
|
|
+ }
|
|
|
+}
|
|
|
+// 删除
|
|
|
+const toDel = async (data) => {
|
|
|
+ let res: IQueryResult = await dictData.del(data._id)
|
|
|
+ if (res.errcode == 0) {
|
|
|
+ ElMessage({ type: `success`, message: `刪除信息成功` })
|
|
|
+ search({ skip, limit })
|
|
|
+ }
|
|
|
+}
|
|
|
+// 选择字典名称
|
|
|
+const changeType = (value) => {
|
|
|
+ dict_type.value = value
|
|
|
+ form.value.dict_type = value
|
|
|
+}
|
|
|
+// 返回
|
|
|
+const toBack = () => {
|
|
|
+ window.history.go(-1)
|
|
|
+}
|
|
|
+// 弹框关闭
|
|
|
+const toClose = () => {
|
|
|
+ form.value = {}
|
|
|
+ searchForm.value = { dict_type: dict_type.value }
|
|
|
+ dialog.value = { title: '信息管理', show: false, type: '1' }
|
|
|
+ search({ skip, limit })
|
|
|
+}
|
|
|
+</script>
|
|
|
+<style lang="scss" scoped>
|
|
|
+.main {
|
|
|
+ .one {
|
|
|
+ margin: 0 0 10px 0;
|
|
|
+ }
|
|
|
+ .two {
|
|
|
+ margin: 0 0 10px 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|