index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <div>
  3. <PlusPage
  4. ref="plusPageInstance"
  5. :columns="tableConfig"
  6. :request="getList"
  7. :is-card="true"
  8. :search="{
  9. labelWidth: 100,
  10. showNumber: 3
  11. }"
  12. :table="{
  13. actionBar: { buttons, type: 'link', width: 180 },
  14. adaptive: { offsetBottom: 50 },
  15. onFormChange: handleTableChange
  16. }"
  17. :pageInfoMap="{ page: 'pageNum', pageSize: 'pageSize' }"
  18. >
  19. <template #table-title>
  20. <el-row class="button-row">
  21. <el-button
  22. v-perms="'ipInterface:index:add'"
  23. size="default"
  24. type="success"
  25. @click="handleCreate"
  26. >
  27. 新增
  28. </el-button>
  29. </el-row>
  30. </template>
  31. </PlusPage>
  32. <!-- 弹窗编辑 -->
  33. <PlusDialogForm
  34. ref="dialogForm"
  35. v-model="form"
  36. v-model:visible="dialogVisible"
  37. :form="{
  38. columns,
  39. labelPosition: 'right',
  40. labelWidth: 100,
  41. rules
  42. }"
  43. :dialog="{ title: dialogTitle + '菜单', width: 600, confirmLoading }"
  44. @confirm="handleSubmit"
  45. @close="handleClose"
  46. />
  47. <PlusDialog
  48. v-model="detailsVisible"
  49. :hasFooter="false"
  50. title="接口配置"
  51. width="500"
  52. >
  53. <PlusDescriptions
  54. :column="24"
  55. :columns="descriptionsColumns"
  56. :data="descriptionsData"
  57. />
  58. </PlusDialog>
  59. </div>
  60. </template>
  61. <script lang="ts" setup>
  62. import { computed, reactive, ref, resolveDirective, toRefs } from "vue";
  63. import type { FormRules } from "element-plus";
  64. import { ElMessage, ElMessageBox } from "element-plus";
  65. import {
  66. type FieldValues,
  67. type PlusColumn,
  68. PlusDescriptions,
  69. PlusDialog,
  70. PlusDialogForm,
  71. PlusPage,
  72. PlusPageInstance,
  73. useTable
  74. } from "plus-pro-components";
  75. import {
  76. addOrEditIpInterface,
  77. deleteIpInterface,
  78. getIpInterfaceList,
  79. switchIpInterfaceStatus
  80. } from "@/api/system/ipInterface";
  81. defineOptions({
  82. name: "IpInterfaceIndex"
  83. });
  84. const plusPageInstance = ref<PlusPageInstance | null>(null);
  85. const getList = async (query: Record<string, any>) => {
  86. let res = await getIpInterfaceList(query);
  87. return {
  88. data: res.list,
  89. total: res.total
  90. };
  91. };
  92. // 重新请求列表接口
  93. const refresh = () => {
  94. plusPageInstance.value?.getList();
  95. };
  96. const handleTableChange = (values: any) => {
  97. console.log(values);
  98. ElMessageBox.confirm("确定修改此数据吗?", "提示", {
  99. confirmButtonText: "确定",
  100. cancelButtonText: "取消",
  101. type: "warning"
  102. })
  103. .then(async () => {
  104. try {
  105. let data = {
  106. id: values.row.id,
  107. status: values.row.status
  108. };
  109. let res = await switchIpInterfaceStatus(data);
  110. if (res.code === 200) {
  111. ElMessage.success("修改成功");
  112. } else {
  113. ElMessage.error(res.msg);
  114. }
  115. } catch (e) {
  116. ElMessage.error("修改失败");
  117. }
  118. })
  119. .finally(() => {
  120. refresh();
  121. });
  122. };
  123. const dialogTitle = computed(() => (state.isCreate ? "新增" : "编辑"));
  124. // 表格数据
  125. const tableConfig: PlusColumn[] = [
  126. {
  127. label: "接口名称",
  128. prop: "interfaceName"
  129. },
  130. {
  131. label: "接口编码",
  132. prop: "interfaceNo",
  133. hideInSearch: true
  134. },
  135. {
  136. label: "接口厂商",
  137. prop: "manufacturer",
  138. hideInSearch: true
  139. },
  140. {
  141. label: "状态",
  142. prop: "status",
  143. valueType: "switch",
  144. fieldProps: {
  145. activeValue: "normal",
  146. inactiveValue: "disable"
  147. },
  148. editable: true,
  149. hideInSearch: true
  150. },
  151. {
  152. label: "状态",
  153. prop: "status",
  154. valueType: "select",
  155. options: [
  156. { label: "正常", value: "normal" },
  157. { label: "停用", value: "disable" }
  158. ],
  159. hideInTable: true
  160. },
  161. {
  162. label: "备注",
  163. prop: "remark",
  164. tableColumnProps: {
  165. showOverflowTooltip: true
  166. },
  167. hideInSearch: true
  168. },
  169. {
  170. label: "创建时间",
  171. prop: "addTime",
  172. valueType: "time-picker",
  173. hideInSearch: true
  174. },
  175. {
  176. label: "创建人",
  177. prop: "addUserName",
  178. hideInSearch: true
  179. }
  180. ];
  181. /*--------------------表单--------------------*/
  182. // 表单实例
  183. const dialogForm = ref(null);
  184. interface State {
  185. dialogVisible: boolean;
  186. detailsVisible: boolean;
  187. confirmLoading: boolean;
  188. selectedIds: number[];
  189. isCreate: boolean;
  190. form: {};
  191. rules: FormRules;
  192. descriptionsData: {};
  193. }
  194. const state = reactive<State>({
  195. dialogVisible: false,
  196. detailsVisible: false,
  197. confirmLoading: false,
  198. selectedIds: [],
  199. isCreate: false,
  200. form: {},
  201. rules: {
  202. interfaceName: [
  203. { required: true, message: "请输入接口名称", trigger: "blur" }
  204. ],
  205. interfaceNo: [
  206. { required: true, message: "请输入接口编码", trigger: "blur" }
  207. ],
  208. manufacturer: [
  209. { required: true, message: "请输入接口厂商", trigger: "blur" }
  210. ],
  211. interfaceConfig: [
  212. { required: true, message: "请输入接口配置", trigger: "blur" }
  213. ]
  214. },
  215. descriptionsData: {}
  216. });
  217. const columns: PlusColumn[] = [
  218. {
  219. label: "接口名称",
  220. prop: "interfaceName",
  221. valueType: "input",
  222. fieldProps: {
  223. clearable: true
  224. }
  225. },
  226. {
  227. label: "接口编码",
  228. prop: "interfaceNo",
  229. valueType: "input",
  230. fieldProps: {
  231. clearable: true
  232. }
  233. },
  234. {
  235. label: "接口厂商",
  236. prop: "manufacturer",
  237. valueType: "input",
  238. fieldProps: {
  239. clearable: true
  240. }
  241. },
  242. {
  243. label: "状态",
  244. prop: "status",
  245. valueType: "radio",
  246. fieldProps: {
  247. options: [
  248. { label: "正常", value: "normal" },
  249. { label: "停用", value: "disable" }
  250. ]
  251. }
  252. },
  253. {
  254. label: "接口配置",
  255. prop: "interfaceConfig",
  256. valueType: "textarea",
  257. fieldProps: {
  258. rows: 4
  259. }
  260. },
  261. {
  262. label: "备注",
  263. prop: "remark",
  264. valueType: "textarea",
  265. fieldProps: {
  266. rows: 4,
  267. maxlength: 200,
  268. showWordLimit: true
  269. }
  270. }
  271. ];
  272. const descriptionsColumns: PlusColumn[] = [
  273. {
  274. label: "接口配置",
  275. prop: "interfaceConfig",
  276. valueType: "copy",
  277. descriptionsItemProps: {
  278. span: 24,
  279. className: "break-all"
  280. }
  281. }
  282. ];
  283. // 创建
  284. const handleCreate = (): void => {
  285. form.value = {
  286. status: "normal"
  287. };
  288. state.isCreate = true;
  289. state.dialogVisible = true;
  290. };
  291. const handleSubmit = async (values: FieldValues) => {
  292. console.log(values, "Submit");
  293. confirmLoading.value = true;
  294. if (state.isCreate) {
  295. try {
  296. let params = form.value;
  297. let res = await addOrEditIpInterface(params);
  298. if (res.code === 200) {
  299. ElMessage.success("新增成功");
  300. confirmLoading.value = false;
  301. dialogVisible.value = false;
  302. } else {
  303. ElMessage.error(res.msg);
  304. }
  305. } finally {
  306. confirmLoading.value = false;
  307. refresh();
  308. }
  309. } else {
  310. // 编辑
  311. try {
  312. let params = form.value;
  313. let res = await addOrEditIpInterface(params);
  314. if (res.code === 200) {
  315. ElMessage.success("修改成功");
  316. confirmLoading.value = false;
  317. dialogVisible.value = false;
  318. refresh();
  319. } else {
  320. ElMessage.error(res.msg);
  321. }
  322. } finally {
  323. confirmLoading.value = false;
  324. refresh();
  325. }
  326. }
  327. };
  328. const handleClose = () => {
  329. console.log(dialogForm.value.formInstance);
  330. dialogForm.value.formInstance.resetFields();
  331. };
  332. // 参数预期管理
  333. const normalizeParams = (params: Record<string, any>) => {
  334. return {
  335. interfaceName: params.interfaceName ?? null,
  336. interfaceNo: params.interfaceNo ?? null,
  337. manufacturer: params.manufacturer ?? null,
  338. status: params.status ?? null,
  339. remark: params.remark ?? null,
  340. interfaceConfig: params.interfaceConfig ?? null,
  341. id: params.id ?? null
  342. };
  343. };
  344. const { buttons } = useTable();
  345. const perms = resolveDirective("perms");
  346. buttons.value = [
  347. {
  348. // 修改
  349. text: "修改",
  350. code: "edit",
  351. // props v0.1.16 版本新增函数类型
  352. props: {
  353. type: "primary"
  354. },
  355. onClick(params) {
  356. // form.value = params.row;
  357. Object.assign(form.value, normalizeParams(params.row));
  358. state.isCreate = false;
  359. state.dialogVisible = true;
  360. },
  361. directives: [[perms, "ipInterface:index:edit"]]
  362. },
  363. {
  364. // 修改
  365. text: "查看配置",
  366. code: "config",
  367. // props v0.1.16 版本新增函数类型
  368. props: {
  369. type: "primary"
  370. },
  371. onClick(val) {
  372. console.log(val);
  373. detailsVisible.value = true;
  374. descriptionsData.value = {
  375. interfaceConfig: val.row.interfaceConfig
  376. };
  377. },
  378. directives: [[perms, "ipInterface:index:detail"]]
  379. },
  380. {
  381. // 删除
  382. text: "删除",
  383. code: "delete",
  384. // props v0.1.16 版本新增计算属性支持
  385. props: computed(() => ({ type: "danger" })),
  386. confirm: {
  387. options: {
  388. draggable: true,
  389. message: "确定删除此数据吗?"
  390. }
  391. },
  392. onConfirm: async params => {
  393. try {
  394. let res = await deleteIpInterface(params.row.id);
  395. if (res.code === 200) {
  396. ElMessage.success("删除成功");
  397. refresh();
  398. } else {
  399. ElMessage.error(res.msg);
  400. }
  401. } catch (e) {
  402. ElMessage.error("删除失败");
  403. }
  404. },
  405. directives: [[perms, "ipInterface:index:remove"]]
  406. }
  407. ];
  408. const {
  409. form,
  410. confirmLoading,
  411. rules,
  412. dialogVisible,
  413. detailsVisible,
  414. descriptionsData
  415. } = toRefs(state);
  416. </script>