index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <!--字典类型-->
  2. <script setup lang="ts">
  3. import {
  4. getDictTypePage,
  5. getDictTypeForm,
  6. addDictType,
  7. updateDictType,
  8. deleteDictTypes,
  9. } from "@/api/system/dict";
  10. import { DictTypePageVO, DictTypeQuery, DictTypeForm } from "@/api/system/dict/types";
  11. import ButtonPermKeys from "@/common/configs/buttonPermission";
  12. defineOptions({
  13. name: "DictType",
  14. inheritAttrs: false,
  15. });
  16. const queryFormRef = ref(ElForm);
  17. const dataFormRef = ref(ElForm);
  18. const loading = ref(false);
  19. const ids = ref<number[]>([]);
  20. const total = ref(0);
  21. const queryParams = reactive<DictTypeQuery>({
  22. pageNo: 1,
  23. pageSize: 10,
  24. });
  25. const dictTypeList = ref<DictTypePageVO[]>();
  26. const dialog = reactive({
  27. title: "",
  28. visible: false,
  29. });
  30. const formData = reactive<DictTypeForm>({
  31. state: 1,
  32. type: "0",
  33. });
  34. const rules = reactive({
  35. dictName: [
  36. { required: true, message: "请输入字典类型名称", trigger: "blur" },
  37. ],
  38. dictType: [
  39. { required: true, message: "请输入字典类型编码", trigger: "blur" },
  40. ],
  41. });
  42. /** 查询 */
  43. function handleQuery() {
  44. loading.value = true;
  45. getDictTypePage(queryParams)
  46. .then(({ data }) => {
  47. dictTypeList.value = data.records;
  48. total.value = data.totalCount;
  49. })
  50. .finally(() => {
  51. loading.value = false;
  52. });
  53. }
  54. /**
  55. * 重置查询
  56. */
  57. function resetQuery() {
  58. queryFormRef.value.resetFields();
  59. queryParams.pageNo = 1;
  60. handleQuery();
  61. }
  62. /** 行复选框选中 */
  63. function handleSelectionChange(selection: any) {
  64. ids.value = selection.map((item: any) => item.id);
  65. }
  66. /**
  67. * 打开字典类型表单弹窗
  68. *
  69. * @param dicTypeId 字典类型ID
  70. */
  71. function openDialog(row?: any) {
  72. dialog.visible = true;
  73. console.log(row);
  74. if (row) {
  75. dialog.title = "修改字典类型";
  76. Object.assign(formData, row);
  77. } else {
  78. formData.id = null;
  79. formData.dictName = "";
  80. formData.dictType = "";
  81. formData.remark = "";
  82. dialog.title = "新增字典类型";
  83. }
  84. }
  85. /** 字典类型表单提交 */
  86. function handleSubmit() {
  87. dataFormRef.value.validate((isValid: boolean) => {
  88. if (isValid) {
  89. const dictTypeId = formData.id;
  90. if (dictTypeId) {
  91. updateDictType(formData)
  92. .then(() => {
  93. ElMessage.success("修改成功");
  94. closeDialog();
  95. handleQuery();
  96. })
  97. .finally(() => (loading.value = false));
  98. } else {
  99. addDictType(formData)
  100. .then(() => {
  101. ElMessage.success("新增成功");
  102. closeDialog();
  103. handleQuery();
  104. })
  105. .finally(() => (loading.value = false));
  106. }
  107. }
  108. });
  109. }
  110. /** 关闭字典类型弹窗 */
  111. function closeDialog() {
  112. dialog.visible = false;
  113. resetForm();
  114. }
  115. /** 重置字典类型表单 */
  116. function resetForm() {
  117. dataFormRef.value.resetFields();
  118. dataFormRef.value.clearValidate();
  119. formData.id = undefined;
  120. formData.state = 1;
  121. }
  122. /** 删除字典类型 */
  123. function handleDelete(dictTypeId?: number) {
  124. const dictTypeIds = [dictTypeId || ids.value].join(",");
  125. if (!dictTypeIds) {
  126. ElMessage.warning("请勾选删除项");
  127. return;
  128. }
  129. ElMessageBox.confirm("确认删除已选中的数据项?", "警告", {
  130. confirmButtonText: "确定",
  131. cancelButtonText: "取消",
  132. type: "warning",
  133. }).then(() => {
  134. deleteDictTypes(dictTypeIds).then(() => {
  135. ElMessage.success("删除成功");
  136. resetQuery();
  137. });
  138. });
  139. }
  140. const dictDataDialog = reactive({
  141. title: "",
  142. visible: false,
  143. });
  144. const selectedDictType = reactive({ typeCode: "", typeName: "" }); // 当前选中的字典类型
  145. /** 打开字典数据弹窗 */
  146. function openDictDialog(row: DictTypeForm) {
  147. dictDataDialog.visible = true;
  148. dictDataDialog.title = "【" + row.dictName + "】字典数据";
  149. selectedDictType.typeCode = row.dictType + "";
  150. selectedDictType.typeName = row.dictName + "";
  151. }
  152. /** 关闭字典数据弹窗 */
  153. function closeDictDialog() {
  154. dictDataDialog.visible = false;
  155. }
  156. onMounted?.(() => {
  157. handleQuery();
  158. });
  159. </script>
  160. <template>
  161. <div class="app-container">
  162. <div class="search-container">
  163. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  164. <el-form-item label="关键字" prop="name">
  165. <el-input
  166. v-model="queryParams.keywords"
  167. placeholder="字典类型名称/编码"
  168. clearable
  169. @keyup.enter="handleQuery"
  170. />
  171. </el-form-item>
  172. <el-form-item>
  173. <el-button type="primary" @click="handleQuery()"
  174. ><i-ep-search />搜索</el-button
  175. >
  176. <el-button @click="resetQuery()"><i-ep-refresh />重置</el-button>
  177. </el-form-item>
  178. </el-form>
  179. </div>
  180. <el-card shadow="never" class="table-container">
  181. <template #header>
  182. <el-button
  183. v-hasPerm="[ButtonPermKeys.SYSTEM.BTNS.dictType_add]"
  184. type="success"
  185. @click="openDialog()"
  186. ><i-ep-plus />新增</el-button
  187. >
  188. <!-- <el-button
  189. type="danger"
  190. :disabled="ids.length === 0"
  191. @click="handleDelete()"
  192. ><i-ep-delete />删除</el-button
  193. > -->
  194. </template>
  195. <el-table
  196. v-loading="loading"
  197. highlight-current-row
  198. :data="dictTypeList"
  199. border
  200. @selection-change="handleSelectionChange"
  201. >
  202. <!-- <el-table-column type="selection" width="55" align="center" /> -->
  203. <el-table-column label="字典类型名称" prop="dictName" width="200" />
  204. <el-table-column label="字典类型编码" prop="dictType" width="200" />
  205. <el-table-column label="状态" align="center" width="100">
  206. <template #default="scope">
  207. <el-tag v-if="scope.row.state === 1" type="success">启用</el-tag>
  208. <el-tag v-else type="info">禁用</el-tag>
  209. </template>
  210. </el-table-column>
  211. <el-table-column label="备注" prop="remark" align="center" />
  212. <el-table-column fixed="right" label="操作" align="center" width="220">
  213. <template #default="scope">
  214. <el-button
  215. type="primary"
  216. link
  217. size="small"
  218. @click.stop="openDictDialog(scope.row)"
  219. ><i-ep-Collection />字典数据</el-button
  220. >
  221. <el-button
  222. v-hasPerm="[ButtonPermKeys.SYSTEM.BTNS.dictType_edit]"
  223. type="primary"
  224. link
  225. size="small"
  226. @click.stop="openDialog(scope.row)"
  227. ><i-ep-edit />编辑</el-button
  228. >
  229. <!-- <el-button
  230. v-hasPerm="[ButtonPermKeys.SYSTEM.BTNS.dictType_del]"
  231. type="primary"
  232. link
  233. size="small"
  234. @click.stop="handleDelete(scope.row.id)"
  235. ><i-ep-delete />删除</el-button
  236. >-->
  237. </template>
  238. </el-table-column>
  239. </el-table>
  240. <pagination
  241. v-if="total > 0"
  242. v-model:total="total"
  243. v-model:page="queryParams.pageNo"
  244. v-model:limit="queryParams.pageSize"
  245. @pagination="handleQuery"
  246. />
  247. </el-card>
  248. <el-dialog
  249. v-model="dialog.visible"
  250. :title="dialog.title"
  251. width="500px"
  252. @close="closeDialog"
  253. >
  254. <el-form
  255. ref="dataFormRef"
  256. :model="formData"
  257. :rules="rules"
  258. label-width="80px"
  259. >
  260. <el-form-item label="字典名称" prop="dictName">
  261. <el-input v-model="formData.dictName" placeholder="请输入字典名称" />
  262. </el-form-item>
  263. <el-form-item label="字典编码" prop="dictType">
  264. <el-input
  265. v-model="formData.dictType"
  266. v-if="formData.id"
  267. placeholder="请输入字典编码 sys_test user_test"
  268. />
  269. <el-input
  270. v-model="formData.dictType"
  271. v-if="!formData.id"
  272. placeholder="请输入字典编码 sys_test user_test"
  273. />
  274. </el-form-item>
  275. <el-form-item label="状态" prop="state">
  276. <el-radio-group v-model="formData.state">
  277. <el-radio :value="1">正常</el-radio>
  278. <el-radio :value="0">停用</el-radio>
  279. </el-radio-group>
  280. </el-form-item>
  281. <!-- <el-form-item label="字典类别" prop="type">
  282. <el-radio-group v-model="formData.type">
  283. <el-radio value="0">用户字典</el-radio>
  284. <el-radio value="1">系统字典</el-radio>
  285. </el-radio-group>
  286. </el-form-item>-->
  287. <el-form-item label="备注" prop="remark">
  288. <el-input
  289. v-model="formData.remark"
  290. type="textarea"
  291. placeholder="字典类型备注"
  292. :autosize="{ minRows: 2, maxRows: 4 }"
  293. />
  294. </el-form-item>
  295. </el-form>
  296. <template #footer>
  297. <div class="dialog-footer">
  298. <el-button type="primary" @click="handleSubmit">确 定</el-button>
  299. <el-button @click="closeDialog">取 消</el-button>
  300. </div>
  301. </template>
  302. </el-dialog>
  303. <!--字典数据弹窗-->
  304. <el-dialog
  305. v-model="dictDataDialog.visible"
  306. :title="dictDataDialog.title"
  307. width="1000px"
  308. @close="closeDictDialog"
  309. >
  310. <dict-item
  311. v-model:typeCode="selectedDictType.typeCode"
  312. v-model:typeName="selectedDictType.typeName"
  313. />
  314. </el-dialog>
  315. </div>
  316. </template>