index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div class="p-2">
  3. <el-card shadow="hover">
  4. <template #header>
  5. <div class="card-header">
  6. <span class="title">首页导航信息列表</span>
  7. <div>
  8. <el-button type="primary" @click="handleAdd" v-hasPermi="['system:navigation:add']">+ 新增</el-button>
  9. <el-button @click="getList">刷新</el-button>
  10. </div>
  11. </div>
  12. </template>
  13. <el-table v-loading="loading" :data="dataList" border>
  14. <el-table-column label="导航标题" prop="navigationName" align="center" />
  15. <el-table-column label="链接地址" prop="url" align="center" show-overflow-tooltip />
  16. <el-table-column label="排序" prop="sort" width="100" align="center" />
  17. <el-table-column label="是否显示" prop="isEnable" width="100" align="center">
  18. <template #default="scope">
  19. {{ scope.row.isEnable === '0' ? '显示' : '不显示' }}
  20. </template>
  21. </el-table-column>
  22. <el-table-column label="操作" width="150" align="center">
  23. <template #default="scope">
  24. <el-button link type="primary" @click="handleUpdate(scope.row)" v-hasPermi="['system:navigation:edit']">编辑</el-button>
  25. <el-button link type="danger" @click="handleDelete(scope.row)" v-hasPermi="['system:navigation:remove']">删除</el-button>
  26. </template>
  27. </el-table-column>
  28. </el-table>
  29. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  30. </el-card>
  31. <!-- 添加或修改对话框 -->
  32. <el-dialog :title="dialog.title" v-model="dialog.visible" width="600px" append-to-body>
  33. <el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
  34. <el-row :gutter="20">
  35. <el-col :span="12">
  36. <el-form-item label="导航标题" prop="navigationName">
  37. <el-input v-model="form.navigationName" placeholder="请输入导航标题" />
  38. </el-form-item>
  39. </el-col>
  40. <el-col :span="12">
  41. <el-form-item label="导航链接" prop="url">
  42. <el-input v-model="form.url" placeholder="请输入导航链接" />
  43. </el-form-item>
  44. </el-col>
  45. </el-row>
  46. <el-row :gutter="20">
  47. <el-col :span="12">
  48. <el-form-item label="排序" prop="sort">
  49. <el-input-number v-model="form.sort" :min="0" controls-position="right" style="width: 100%" />
  50. </el-form-item>
  51. </el-col>
  52. <el-col :span="12">
  53. <el-form-item label="是否启用" prop="isEnable">
  54. <el-switch v-model="form.isEnable" active-value="0" inactive-value="1" />
  55. </el-form-item>
  56. </el-col>
  57. </el-row>
  58. <el-form-item label="描述" prop="remark">
  59. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  60. </el-form-item>
  61. </el-form>
  62. <template #footer>
  63. <div class="dialog-footer">
  64. <el-button type="primary" @click="submitForm">确 认</el-button>
  65. <el-button @click="cancel">取 消</el-button>
  66. </div>
  67. </template>
  68. </el-dialog>
  69. </div>
  70. </template>
  71. <script setup name="HomeNav" lang="ts">
  72. import { listNavigation, getNavigation, addNavigation, updateNavigation, delNavigation } from '@/api/system/navigation';
  73. import { ComponentInternalInstance, getCurrentInstance, ref, reactive, toRefs } from 'vue';
  74. import type { FormInstance } from 'element-plus';
  75. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  76. const dataList = ref([]);
  77. const loading = ref(true);
  78. const total = ref(0);
  79. const formRef = ref<FormInstance>();
  80. const dialog = reactive({ visible: false, title: '' });
  81. const data = reactive({
  82. form: {} as any,
  83. queryParams: {
  84. pageNum: 1,
  85. pageSize: 10,
  86. navType: 'setting_home'
  87. },
  88. rules: {
  89. navigationName: [{ required: true, message: '导航名称不能为空', trigger: 'blur' }],
  90. url: [{ required: true, message: '链接地址不能为空', trigger: 'blur' }],
  91. sort: [{ required: true, message: '排序不能为空', trigger: 'blur' }],
  92. isEnable: [{ required: true, message: '请选择是否显示', trigger: 'change' }]
  93. }
  94. });
  95. const { queryParams, form, rules } = toRefs(data);
  96. const getList = async () => {
  97. loading.value = true;
  98. const res = await listNavigation(queryParams.value);
  99. dataList.value = res.rows;
  100. total.value = res.total;
  101. loading.value = false;
  102. };
  103. const reset = () => {
  104. form.value = {
  105. id: undefined,
  106. navType: 'setting_home',
  107. navigationName: undefined,
  108. url: undefined,
  109. sort: 0,
  110. isEnable: '0',
  111. remark: undefined
  112. };
  113. formRef.value?.resetFields();
  114. };
  115. const handleAdd = () => {
  116. reset();
  117. dialog.visible = true;
  118. dialog.title = '添加首页导航';
  119. };
  120. const handleUpdate = async (row: any) => {
  121. reset();
  122. const res = await getNavigation(row.id);
  123. Object.assign(form.value, res.data);
  124. dialog.visible = true;
  125. dialog.title = '修改首页导航';
  126. };
  127. const submitForm = () => {
  128. formRef.value.validate(async (valid: boolean) => {
  129. if (valid) {
  130. if (form.value.id) {
  131. await updateNavigation(form.value);
  132. proxy?.$modal.msgSuccess('修改成功');
  133. } else {
  134. await addNavigation(form.value);
  135. proxy?.$modal.msgSuccess('新增成功');
  136. }
  137. dialog.visible = false;
  138. getList();
  139. }
  140. });
  141. };
  142. const handleDelete = async (row: any) => {
  143. await proxy?.$modal.confirm('是否确认删除?');
  144. await delNavigation(row.id);
  145. proxy?.$modal.msgSuccess('删除成功');
  146. getList();
  147. };
  148. const cancel = () => {
  149. dialog.visible = false;
  150. reset();
  151. };
  152. getList();
  153. </script>
  154. <style scoped>
  155. .card-header {
  156. display: flex;
  157. justify-content: space-between;
  158. align-items: center;
  159. }
  160. .card-header .title {
  161. font-size: 16px;
  162. font-weight: bold;
  163. }
  164. </style>