index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight">
  5. <el-col :span="24" class="one">
  6. <component :is="search1" :form="searchForm" @onSubmit="toSearch" @toReset="toReset"></component>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <cButton @toAdd="toAdd()"> </cButton>
  10. </el-col>
  11. <el-col :span="24" class="thr">
  12. <cTable :fields="fields" :opera="opera" :data="list" @query="search" :total="total" @edit="toEdit" @del="toDel" >
  13. <template #dict_type="{ item, row }">
  14. <template v-if="item.model === 'dict_type'">
  15. <el-link size="small" type="primary" @click="toType(row)">{{ getProps(row, item.model) }}</el-link>
  16. </template>
  17. </template>
  18. </cTable>
  19. </el-col>
  20. </el-col>
  21. </el-row>
  22. <cDialog :dialog="dialog" @handleClose="toClose">
  23. <template v-slot:info>
  24. <cForm v-if="dialog.type == '1'" :span="24" :fields="formFields" :form="form" :rules="rules" @save="onSubmit">
  25. <template #status>
  26. <el-radio label="0">正常</el-radio>
  27. <el-radio label="1">停用</el-radio>
  28. </template>
  29. </cForm>
  30. </template>
  31. </cDialog>
  32. </div>
  33. </template>
  34. <script lang="ts" setup>
  35. import _ from 'lodash'
  36. import search1 from './parts/search-1.vue'
  37. import type { FormRules } from 'element-plus'
  38. import type { Ref } from 'vue'
  39. import { ref, onMounted, getCurrentInstance, reactive } from 'vue'
  40. import { ElMessage } from 'element-plus'
  41. import { useRouter } from 'vue-router'
  42. import { DictTypeStore } from '@common/src/stores/system/dictType' // 字典表
  43. import type { IQueryResult } from '@/util/types.util'
  44. const dictType = DictTypeStore()
  45. const router = useRouter()
  46. const { proxy } = getCurrentInstance() as any
  47. // 列表数据
  48. let list: Ref<any[]> = ref([])
  49. // 总数
  50. let total: Ref<number> = ref(0)
  51. let skip = 0
  52. let limit: number = proxy.$limit
  53. // 列表
  54. let fields: Ref<any[]> = ref([
  55. { label: '字典名称', model: 'dict_name' },
  56. { label: '字典类型', model: 'dict_type', custom: true },
  57. { label: '状态', model: 'status', format: (i) => (i == '0' ? '正常' : '停用') },
  58. { label: '备注', model: 'remark' }
  59. ])
  60. // 操作
  61. let opera: Ref<any[]> = ref([
  62. { label: '修改', method: 'edit' },
  63. { label: '删除', method: 'del', confirm: true, type: 'danger' }
  64. ])
  65. const dialog: Ref<{ type: string; show: boolean; title: string }> = ref({ type: '1', show: false, title: '信息管理' })
  66. let form: Ref<{}> = ref({})
  67. // 表单
  68. let formFields: Ref<any[]> = ref([
  69. { label: '字典名称', model: 'dict_name' },
  70. { label: '字典类型', model: 'dict_type' },
  71. { label: '状态', model: 'status', type: 'radio' },
  72. { label: '备注', model: 'remark', type: 'textarea' }
  73. ])
  74. const rules = reactive<FormRules>({
  75. dict_type: [{ required: true, message: '请输入字典类型', trigger: 'blur' }],
  76. dict_label: [{ required: true, message: '请输入字典标签', trigger: 'blur' }],
  77. dict_value: [{ required: true, message: '请输入字典键值', trigger: 'blur' }],
  78. dict_sort: [{ required: true, message: '请输入显示排序', trigger: 'blur' }],
  79. status: [{ required: true, message: '请选择状态', trigger: 'change' }]
  80. })
  81. // 查询数据
  82. let searchForm: Ref<{}> = ref({})
  83. onMounted(async () => {
  84. await search({ skip, limit })
  85. })
  86. // 查询
  87. const search = async (e: { skip: number; limit: number }) => {
  88. const { skip, limit } = e
  89. const condition = _.cloneDeep(searchForm.value)
  90. let info = { limit: limit, skip: skip, ...condition }
  91. // let res: IQueryResult = await dictType.query(info)
  92. // if (res.errcode == 0) {
  93. // list.value = res.data as any[]
  94. // total.value = res.total
  95. // }
  96. }
  97. const toSearch = () => {
  98. search({ skip, limit })
  99. }
  100. const toReset = () => {
  101. searchForm.value = {}
  102. search({ skip, limit })
  103. }
  104. // 新增
  105. const toAdd = () => {
  106. dialog.value = { title: '信息管理', show: true, type: '1' }
  107. }
  108. // 修改
  109. const toEdit = async (data) => {
  110. // let res: IQueryResult = await dictType.fetch(data._id)
  111. // if (res.errcode == 0) {
  112. // form.value = res.data as {}
  113. // dialog.value = { title: '信息管理', show: true, type: '1' }
  114. // }
  115. }
  116. // 提交
  117. const onSubmit = async (data) => {
  118. // let res: IQueryResult
  119. // if (data._id) res = await dictType.update(data)
  120. // else res = await dictType.create(data)
  121. // if (res.errcode == 0) {
  122. // ElMessage({ type: `success`, message: `维护信息成功` })
  123. // toClose()
  124. // }
  125. }
  126. // 删除
  127. const toDel = async (data) => {
  128. // let res: IQueryResult = await dictType.del(data._id)
  129. // if (res.errcode == 0) {
  130. // ElMessage({ type: `success`, message: `刪除信息成功` })
  131. // search({ skip, limit })
  132. // }
  133. }
  134. // 字典类型跳转
  135. const toType = (data) => {
  136. router.push({ path: '/system/dict/detail', query: { id: data._id, dict_type: data.dict_type } })
  137. }
  138. // 弹框关闭
  139. const toClose = () => {
  140. form.value = {}
  141. searchForm.value = {}
  142. dialog.value = { title: '信息管理', show: false, type: '1' }
  143. search({ skip, limit })
  144. }
  145. const getProps = (data, prop) => {
  146. return _.get(data, prop)
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. .main {
  151. .one {
  152. margin: 0 0 10px 0;
  153. }
  154. .two {
  155. margin: 0 0 10px 0;
  156. }
  157. }
  158. </style>