index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <!-- 搜索工作栏 -->
  3. <content-wrap>
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="字典名称" prop="name">
  12. <el-input
  13. v-model="queryParams.name"
  14. placeholder="请输入字典名称"
  15. clearable
  16. style="width: 240px"
  17. @keyup.enter="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item label="字典类型" prop="type">
  21. <el-input
  22. v-model="queryParams.type"
  23. placeholder="请输入字典类型"
  24. clearable
  25. style="width: 240px"
  26. @keyup.enter="handleQuery"
  27. />
  28. </el-form-item>
  29. <el-form-item label="状态" prop="status">
  30. <el-select
  31. v-model="queryParams.status"
  32. placeholder="字典状态"
  33. clearable
  34. style="width: 240px"
  35. >
  36. <el-option
  37. v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
  38. :key="parseInt(dict.value)"
  39. :label="dict.label"
  40. :value="dict.value"
  41. />
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item label="创建时间" prop="createTime">
  45. <el-date-picker
  46. v-model="queryParams.createTime"
  47. style="width: 240px"
  48. value-format="yyyy-MM-dd HH:mm:ss"
  49. type="daterange"
  50. range-separator="-"
  51. start-placeholder="开始日期"
  52. end-placeholder="结束日期"
  53. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  54. />
  55. </el-form-item>
  56. <el-form-item>
  57. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  58. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  59. <el-button type="primary" @click="openModal('create')" v-hasPermi="['system:dict:create']">
  60. <Icon icon="ep:plus" class="mr-5px" /> 新增
  61. </el-button>
  62. <el-button
  63. type="success"
  64. plain
  65. @click="handleExport"
  66. :loading="exportLoading"
  67. v-hasPermi="['system:dict:export']"
  68. >
  69. <Icon icon="ep:download" class="mr-5px" /> 导出
  70. </el-button>
  71. </el-form-item>
  72. </el-form>
  73. </content-wrap>
  74. <!-- 列表 -->
  75. <content-wrap>
  76. <el-table v-loading="loading" :data="list">
  77. <el-table-column label="字典编号" align="center" prop="id" />
  78. <el-table-column label="字典名称" align="center" prop="name" show-overflow-tooltip />
  79. <el-table-column label="字典类型" align="center" prop="type" width="300" />
  80. <el-table-column label="状态" align="center" prop="status">
  81. <template #default="scope">
  82. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  83. </template>
  84. </el-table-column>
  85. <el-table-column label="备注" align="center" prop="remark" />
  86. <el-table-column
  87. label="创建时间"
  88. :formatter="dateFormatter"
  89. align="center"
  90. prop="createTime"
  91. width="180"
  92. />
  93. <el-table-column label="操作" align="center">
  94. <template #default="scope">
  95. <el-button
  96. link
  97. type="primary"
  98. @click="openModal('update', scope.row.id)"
  99. v-hasPermi="['system:dict:update']"
  100. >
  101. 修改
  102. </el-button>
  103. <router-link :to="'/dict/type/data/' + scope.row.type">
  104. <el-button link type="primary">数据</el-button>
  105. </router-link>
  106. <el-button
  107. link
  108. type="danger"
  109. @click="handleDelete(scope.row.id)"
  110. v-hasPermi="['system:dict:delete']"
  111. >
  112. 删除
  113. </el-button>
  114. </template>
  115. </el-table-column>
  116. </el-table>
  117. <!-- 分页 -->
  118. <Pagination
  119. :total="total"
  120. v-model:page="queryParams.pageNo"
  121. v-model:limit="queryParams.pageSize"
  122. @pagination="getList"
  123. />
  124. </content-wrap>
  125. <!-- 表单弹窗:添加/修改 -->
  126. <dict-type-form ref="modalRef" @success="getList" />
  127. </template>
  128. <script setup lang="ts" name="Dict">
  129. import { getDictOptions, DICT_TYPE } from '@/utils/dict'
  130. import { dateFormatter } from '@/utils/formatTime'
  131. import * as DictTypeApi from '@/api/system/dict/dict.type'
  132. import DictTypeForm from './form.vue'
  133. import download from '@/utils/download'
  134. const message = useMessage() // 消息弹窗
  135. const { t } = useI18n() // 国际化
  136. const loading = ref(true) // 列表的加载中
  137. const total = ref(0) // 列表的总页数
  138. const list = ref([]) // 字典表格数据
  139. const queryParams = reactive({
  140. pageNo: 1,
  141. pageSize: 10,
  142. name: '',
  143. type: '',
  144. status: undefined,
  145. createTime: []
  146. })
  147. const queryFormRef = ref() // 搜索的表单
  148. const exportLoading = ref(false) // 导出的加载中
  149. /** 查询字典类型列表 */
  150. const getList = async () => {
  151. loading.value = true
  152. try {
  153. const data = await DictTypeApi.getDictTypePage(queryParams)
  154. list.value = data.list
  155. total.value = data.total
  156. } finally {
  157. loading.value = false
  158. }
  159. }
  160. /** 搜索按钮操作 */
  161. const handleQuery = () => {
  162. queryParams.pageNo = 1
  163. getList()
  164. }
  165. /** 重置按钮操作 */
  166. const resetQuery = () => {
  167. queryFormRef.value.resetFields()
  168. handleQuery()
  169. }
  170. /** 添加/修改操作 */
  171. const modalRef = ref()
  172. const openModal = (type: string, id?: number) => {
  173. modalRef.value.openModal(type, id)
  174. }
  175. /** 删除按钮操作 */
  176. const handleDelete = async (id: number) => {
  177. try {
  178. // 删除的二次确认
  179. await message.delConfirm()
  180. // 发起删除
  181. await DictTypeApi.deleteDictType(id)
  182. message.success(t('common.delSuccess'))
  183. // 刷新列表
  184. await getList()
  185. } catch {}
  186. }
  187. /** 导出按钮操作 */
  188. const handleExport = async () => {
  189. try {
  190. // 导出的二次确认
  191. await message.exportConfirm()
  192. // 发起导出
  193. exportLoading.value = true
  194. const data = await DictTypeApi.exportDictType(queryParams)
  195. download.excel(data, '字典类型.xls')
  196. } catch {
  197. } finally {
  198. exportLoading.value = false
  199. }
  200. }
  201. /** 初始化 **/
  202. onMounted(() => {
  203. getList()
  204. })
  205. </script>