index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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="success" @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="orgDict">
  116. import {defineAsyncComponent, reactive, onMounted, ref, getCurrentInstance, nextTick} from 'vue';
  117. import {$body} from "/@/utils/request";
  118. import u from "/@/utils/u";
  119. import {Msg} from "/@/utils/message";
  120. // 引入组件
  121. const {proxy}: any = getCurrentInstance();
  122. import {ElButton} from 'element-plus'
  123. // 定义变量内容
  124. const queryRef = ref();
  125. const dicDialogRef = ref();
  126. const state = reactive({
  127. tableData: {
  128. data: [] as Array<any>,
  129. total: 0,
  130. loading: false,
  131. height: 500
  132. },
  133. pageQuery: {
  134. pageNum: 1,
  135. pageSize: 10240,
  136. total: 0
  137. },
  138. formQuery: {},
  139. columns: [
  140. {label: '编码', prop: 'code', query: true, type: 'text', resizable: true, width: 250, fixed: 'left'},
  141. {label: '备注', prop: 'remark', query: true, type: 'text', resizable: true, width: 160},
  142. {
  143. label: '操作时间', prop: 'updateTime', width: 180, query: true, type: 'datetime', resizable: true,
  144. }
  145. ],
  146. dictForm: {
  147. visible: false,
  148. id: 0,
  149. code: '',
  150. remark: '',
  151. list: [] as Array<any>
  152. } as any,
  153. dictLoading: false,
  154. visible: false,
  155. saveVisible: false,
  156. dictList: [] as any[]
  157. });
  158. // 初始化表格数据
  159. const loadData = (refresh: boolean = false) => {
  160. if (refresh) {
  161. state.pageQuery.pageNum = 1;
  162. }
  163. state.tableData.loading = true;
  164. $body('dataDict/list', state.formQuery).then((res: any) => {
  165. state.dictList = res;
  166. state.tableData.data = u.distinctByKey(res, "code");
  167. state.tableData.loading = false;
  168. })
  169. };
  170. /*// 打开新增字典弹窗
  171. const onOpenAddDic = (type: string) => {
  172. //console.log(type)
  173. dicDialogRef.value.openDialog(type);
  174. };
  175. // 打开修改字典弹窗
  176. const onOpenEditDic = (type: string, row: RowDicType) => {
  177. //console.log(row)
  178. dicDialogRef.value.openDialog(type, row);
  179. };*/
  180. // 删除字典
  181. const onRowDel = (row: RowDicType) => {
  182. //console.log(row)
  183. Msg.confirm(`此操作将永久删除字典名称:“${row.type}”,是否继续?`).then(() => {
  184. loadData();
  185. Msg.message("删除成功")
  186. })
  187. }
  188. // 页面加载时
  189. onMounted(() => {
  190. loadData();
  191. nextTick(() => {
  192. let bodyHeight = document.body.clientHeight;
  193. let queryHeight = queryRef.value.$el.clientHeight;
  194. state.tableData.height = bodyHeight - queryHeight - 320
  195. })
  196. });
  197. const handleDictRowClick = (row: any) => {
  198. state.dictLoading = true;
  199. let list = state.dictList.filter(k => k.code === row.code);
  200. if (u.isEmptyOrNull(list)) {
  201. state.dictForm = {
  202. id: 0,
  203. code: '',
  204. remark: '',
  205. list: []
  206. }
  207. return;
  208. }
  209. u.sort(list, 'weight');
  210. state.dictForm = {
  211. id: list[0].id,
  212. code: list[0].code,
  213. remark: list[0].remark,
  214. list: list
  215. }
  216. state.visible = true;
  217. }
  218. const handleDeleteDictItem = (idx) => {
  219. state.saveVisible = true;
  220. state.dictForm.list.splice(idx, 1)
  221. }
  222. const handleAddDict = () => {
  223. state.saveVisible = true;
  224. state.visible = true;
  225. state.dictForm = {
  226. code: '字典码值',
  227. remark: '备注',
  228. list: [
  229. {name: '', value: '', weight: 0}
  230. ]
  231. }
  232. }
  233. const handleAddDictItem = () => {
  234. state.saveVisible = true;
  235. state.dictForm.list.push({
  236. code: '',
  237. name: '',
  238. value: '',
  239. remark: '',
  240. weight: 0
  241. })
  242. }
  243. const handleSaveDict = () => {
  244. let params = state.dictForm.list.map(k => {
  245. let {id, name, value, weight} = k;
  246. if (!name) {
  247. throw Error("字典项名称不能为空");
  248. }
  249. if (!value) {
  250. throw Error("字典项码值不能为空");
  251. }
  252. return {
  253. id, name, value, weight,
  254. code: state.dictForm.code,
  255. remark: state.dictForm.remark
  256. }
  257. })
  258. $body(`dataDict/saveOrUpdate`, params).then(() => {
  259. Msg.message("保存成功")
  260. state.saveVisible = false;
  261. state.dictForm = {
  262. id: 0,
  263. code: '',
  264. remark: '',
  265. list: [] as Array<any>
  266. }
  267. })
  268. }
  269. </script>
  270. <style scoped lang="scss">
  271. .system-container {
  272. :deep(.el-card__body) {
  273. display: flex;
  274. flex-direction: column;
  275. flex: 1;
  276. overflow: auto;
  277. .el-table {
  278. flex: 1;
  279. }
  280. }
  281. }
  282. .page-content {
  283. margin-bottom: 20px;
  284. }
  285. .page-pager {
  286. background-color: #fff;
  287. height: 24px;
  288. }
  289. </style>