index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <div class="system-container layout-padding">
  3. <el-card shadow="hover" class="layout-padding-auto">
  4. <el-form
  5. :model="state.formQuery"
  6. ref="queryRef"
  7. size="default" label-width="0px" class="mt5 mb5">
  8. <!-- <el-input
  9. v-model="state.formQuery.name"
  10. placeholder="字典名称"
  11. clearable
  12. @blur="loadData(true)"
  13. class="wd150 mr10">
  14. </el-input>-->
  15. <el-input
  16. v-model="state.formQuery.code"
  17. placeholder="字典编码"
  18. clearable
  19. @blur="loadData(true)"
  20. class="wd150 mr10">
  21. </el-input>
  22. <el-button class="ml10" plain size="default" type="success" @click="loadData(true)">
  23. <SvgIcon name="ele-Search"/>
  24. 查询
  25. </el-button>
  26. <el-button class="ml10" plain size="default" type="primary" @click="handleAddDict" v-auth="'dict.add'">
  27. <SvgIcon name="ele-FolderAdd"/>
  28. 创建
  29. </el-button>
  30. </el-form>
  31. <div class="flex">
  32. <el-table
  33. style="width: 400px;"
  34. width="400"
  35. border
  36. stripe="stripe"
  37. :height="state.tableData.height"
  38. highlight-current-row
  39. current-row-key="id"
  40. row-key="id"
  41. :data="state.tableData.data"
  42. @row-click="handleDictRowClick"
  43. v-loading="state.tableData.loading">
  44. <template #empty>
  45. <el-empty></el-empty>
  46. </template>
  47. <el-table-column
  48. v-for="field in state.columns"
  49. :key="field.prop"
  50. :label="field.label"
  51. :column-key="field.prop"
  52. :width="field.width"
  53. :min-width="field.minWidth"
  54. :fixed="field.fixed"
  55. :sortable="field.sortable"
  56. :show-overflow-tooltip="!field.fixed&&field.width>150"
  57. >
  58. <template #default="{row}">
  59. <template v-if="field.prop==='expand'">
  60. <p style="padding-left: 2em;" v-html="row[field.prop]"></p>
  61. </template>
  62. <template v-else>
  63. <div>{{ row[field.prop] }}</div>
  64. </template>
  65. </template>
  66. </el-table-column>
  67. </el-table>
  68. <div class="dict-content__box flex-auto ml10 pr5 pl5" v-if="state.visible">
  69. <el-input
  70. :readonly="state.dictForm.id"
  71. v-model="state.dictForm.code"
  72. placeholder="字典编码"
  73. clearable
  74. size="default"
  75. class="w100 mr10">
  76. </el-input>
  77. <el-input
  78. v-model="state.dictForm.remark"
  79. placeholder="备注"
  80. clearable
  81. type="textarea"
  82. size="default"
  83. :rows="2"
  84. class="w100 mt10">
  85. </el-input>
  86. <el-row :gutter="10" class="mt20">
  87. <el-col :span="8">字典项名称</el-col>
  88. <el-col :span="8">字典项码值</el-col>
  89. <el-col :span="4">排序权重</el-col>
  90. </el-row>
  91. <div v-for="(item,idx) in state.dictForm.list" :key="idx" class="mt10">
  92. <el-row :gutter="10">
  93. <el-col :span="8">
  94. <el-input size="default" v-model="item.name" placeholder="字典名称" @change="state.saveVisible = true;"></el-input>
  95. </el-col>
  96. <el-col :span="8">
  97. <el-input size="default" :readonly="item.id" v-model="item.value" placeholder="字典码值"></el-input>
  98. </el-col>
  99. <el-col :span="8">
  100. <el-input-number :min="1" size="default" controls-position="right" v-model="item.weight" placeholder="排序权重"></el-input-number>
  101. <SvgIcon name="ele-RemoveFilled" color="var(--el-color-danger)" class="ml3 cursor-pointer" @click="handleDeleteDictItem(idx)"></SvgIcon>
  102. </el-col>
  103. </el-row>
  104. </div>
  105. <el-button v-auth="'dict.add'" size="small" class="mt10 mr5" type="primary" @click="handleAddDictItem">新增</el-button>
  106. <el-button v-auth="'dict.modify'" size="small" class="mt10" type="success" v-if="state.saveVisible" @click="handleSaveDict">保存</el-button>
  107. </div>
  108. </div>
  109. <!-- <el-affix position="bottom" :offset="49">
  110. <ext-page class="page-pager" v-model:value="state.pageQuery" @change="loadData(false)"/>
  111. </el-affix>-->
  112. </el-card>
  113. </div>
  114. </template>
  115. <script setup lang="ts" name="Dict">
  116. import {defineAsyncComponent, reactive, onMounted, ref, getCurrentInstance, nextTick} from 'vue';
  117. import ExtPage from "/@/components/form/ExtPage.vue"
  118. import {$body} from "/@/utils/request";
  119. import u from "/@/utils/u";
  120. import {Msg} from "/@/utils/message";
  121. // 引入组件
  122. const {proxy}: any = getCurrentInstance();
  123. import {ElButton} from 'element-plus'
  124. // 定义变量内容
  125. const queryRef = ref();
  126. const dicDialogRef = ref();
  127. const state = reactive({
  128. tableData: {
  129. data: [] as Array<any>,
  130. total: 0,
  131. loading: false,
  132. height: 500
  133. },
  134. pageQuery: {
  135. pageNum: 1,
  136. pageSize: 10240,
  137. total: 0
  138. },
  139. formQuery: {},
  140. columns: [
  141. {label: '编码', prop: 'code', query: true, type: 'text', resizable: true, width: 250, fixed: 'left'},
  142. {label: '备注', prop: 'remark', query: true, type: 'text', resizable: true, width: 160},
  143. {
  144. label: '操作时间', prop: 'updateTime', width: 180, query: true, type: 'datetime', resizable: true,
  145. }
  146. ],
  147. dictForm: {
  148. visible:false,
  149. id: 0,
  150. code: '',
  151. remark: '',
  152. list: [] as Array<any>
  153. },
  154. dictLoading: false,
  155. visible:false,
  156. saveVisible:false,
  157. dictList:[] as any[]
  158. });
  159. // 初始化表格数据
  160. const loadData = (refresh: boolean = false) => {
  161. if (refresh) {
  162. state.pageQuery.pageNum = 1;
  163. }
  164. state.tableData.loading = true;
  165. $body('dataDict/list', state.formQuery).then((res: any) => {
  166. state.dictList = res;
  167. state.tableData.data = u.distinctByKey(res,"code");
  168. state.tableData.loading = false;
  169. })
  170. };
  171. /*// 打开新增字典弹窗
  172. const onOpenAddDic = (type: string) => {
  173. console.log(type)
  174. dicDialogRef.value.openDialog(type);
  175. };
  176. // 打开修改字典弹窗
  177. const onOpenEditDic = (type: string, row: RowDicType) => {
  178. console.log(row)
  179. dicDialogRef.value.openDialog(type, row);
  180. };*/
  181. // 删除字典
  182. const onRowDel = (row: RowDicType) => {
  183. console.log(row)
  184. Msg.confirm(`此操作将永久删除字典名称:“${row.type}”,是否继续?`).then(() => {
  185. loadData();
  186. Msg.message("删除成功")
  187. })
  188. }
  189. // 页面加载时
  190. onMounted(() => {
  191. loadData();
  192. nextTick(() => {
  193. let bodyHeight = document.body.clientHeight;
  194. let queryHeight = queryRef.value.$el.clientHeight;
  195. state.tableData.height = bodyHeight - queryHeight - 320
  196. })
  197. });
  198. const handleDictRowClick = (row: any) => {
  199. state.dictLoading = true;
  200. let list = state.dictList.filter(k=>k.code===row.code);
  201. if (u.isEmptyOrNull(list)) {
  202. state.dictForm = {
  203. id:0,
  204. code: '',
  205. remark: '',
  206. list: []
  207. }
  208. return;
  209. }
  210. u.sort(list, 'weight');
  211. state.dictForm = {
  212. id: list[0].id,
  213. code: list[0].code,
  214. remark: list[0].remark,
  215. list: list
  216. }
  217. state.visible = true;
  218. }
  219. const handleDeleteDictItem = (idx) => {
  220. state.saveVisible = true;
  221. state.dictForm.list.splice(idx,1)
  222. }
  223. const handleAddDict = () => {
  224. state.saveVisible = true;
  225. state.visible = true;
  226. state.dictForm = {
  227. code: '字典码值',
  228. remark: '备注',
  229. list: [
  230. {name: '', value: '', weight: 0}
  231. ]
  232. }
  233. }
  234. const handleAddDictItem = () => {
  235. state.saveVisible = true;
  236. state.dictForm.list.push({
  237. code: '',
  238. name: '',
  239. value: '',
  240. remark: '',
  241. weight: 0
  242. })
  243. }
  244. const handleSaveDict = () => {
  245. let params = state.dictForm.list.map(k => {
  246. let {id, name, value, weight} = k;
  247. if(!name){
  248. throw Error("字典项名称不能为空");
  249. }
  250. if(!value){
  251. throw Error("字典项码值不能为空");
  252. }
  253. return {
  254. id, name, value, weight,
  255. code: state.dictForm.code,
  256. remark: state.dictForm.remark
  257. }
  258. })
  259. $body(`dataDict/saveOrUpdate`, params).then(() => {
  260. Msg.message("保存成功")
  261. state.saveVisible = false;
  262. })
  263. }
  264. </script>
  265. <style scoped lang="scss">
  266. .system-container {
  267. :deep(.el-card__body) {
  268. display: flex;
  269. flex-direction: column;
  270. flex: 1;
  271. overflow: auto;
  272. .el-table {
  273. flex: 1;
  274. }
  275. }
  276. }
  277. .page-content {
  278. margin-bottom: 20px;
  279. }
  280. .page-pager {
  281. background-color: #fff;
  282. height: 24px;
  283. }
  284. </style>