index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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="500px" append-to-body>
  33. <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
  34. <el-form-item label="导航名称" prop="navigationName">
  35. <el-input v-model="form.navigationName" placeholder="请输入导航名称" />
  36. </el-form-item>
  37. <el-form-item label="链接地址" prop="url">
  38. <el-input v-model="form.url" placeholder="请输入链接地址" />
  39. </el-form-item>
  40. <el-form-item label="排序" prop="sort">
  41. <el-input-number v-model="form.sort" :min="0" />
  42. </el-form-item>
  43. <el-form-item label="是否启用" prop="isEnable">
  44. <el-radio-group v-model="form.isEnable">
  45. <el-radio value="0">是</el-radio>
  46. <el-radio value="1">否</el-radio>
  47. </el-radio-group>
  48. </el-form-item>
  49. </el-form>
  50. <template #footer>
  51. <div class="dialog-footer">
  52. <el-button type="primary" @click="submitForm">确 定</el-button>
  53. <el-button @click="cancel">取 消</el-button>
  54. </div>
  55. </template>
  56. </el-dialog>
  57. </div>
  58. </template>
  59. <script setup name="FloatNav" lang="ts">
  60. import { listNavigation, getNavigation, addNavigation, updateNavigation, delNavigation } from '@/api/system/navigation';
  61. import { ComponentInternalInstance, getCurrentInstance, ref, reactive, toRefs } from 'vue';
  62. import type { FormInstance } from 'element-plus';
  63. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  64. const dataList = ref([]);
  65. const loading = ref(true);
  66. const total = ref(0);
  67. const formRef = ref<FormInstance>();
  68. const dialog = reactive({ visible: false, title: '' });
  69. const data = reactive({
  70. form: {} as any,
  71. queryParams: {
  72. pageNum: 1,
  73. pageSize: 10,
  74. navType: 'float'
  75. },
  76. rules: {
  77. navigationName: [{ required: true, message: '导航名称不能为空', trigger: 'blur' }],
  78. url: [{ required: true, message: '链接地址不能为空', trigger: 'blur' }],
  79. sort: [{ required: true, message: '排序不能为空', trigger: 'blur' }],
  80. isEnable: [{ required: true, message: '请选择是否启用', trigger: 'change' }]
  81. }
  82. });
  83. const { queryParams, form, rules } = toRefs(data);
  84. const getList = async () => {
  85. loading.value = true;
  86. const res = await listNavigation(queryParams.value);
  87. dataList.value = res.rows;
  88. total.value = res.total;
  89. loading.value = false;
  90. };
  91. const reset = () => {
  92. form.value = {
  93. id: undefined,
  94. navType: 'float',
  95. navigationName: undefined,
  96. url: undefined,
  97. sort: 0,
  98. isEnable: '0'
  99. };
  100. formRef.value?.resetFields();
  101. };
  102. const handleAdd = () => {
  103. reset();
  104. dialog.visible = true;
  105. dialog.title = '添加浮动导航';
  106. };
  107. const handleUpdate = async (row: any) => {
  108. reset();
  109. const res = await getNavigation(row.id);
  110. Object.assign(form.value, res.data);
  111. dialog.visible = true;
  112. dialog.title = '修改浮动导航';
  113. };
  114. const submitForm = () => {
  115. formRef.value?.validate(async (valid: boolean) => {
  116. if (valid) {
  117. if (form.value.id) {
  118. await updateNavigation(form.value);
  119. proxy?.$modal.msgSuccess('修改成功');
  120. } else {
  121. await addNavigation(form.value);
  122. proxy?.$modal.msgSuccess('新增成功');
  123. }
  124. dialog.visible = false;
  125. getList();
  126. }
  127. });
  128. };
  129. const handleDelete = async (row: any) => {
  130. await proxy?.$modal.confirm('是否确认删除?');
  131. await delNavigation(row.id);
  132. proxy?.$modal.msgSuccess('删除成功');
  133. getList();
  134. };
  135. const cancel = () => {
  136. dialog.visible = false;
  137. reset();
  138. };
  139. getList();
  140. </script>
  141. <style scoped>
  142. .card-header {
  143. display: flex;
  144. justify-content: space-between;
  145. align-items: center;
  146. }
  147. .card-header .title {
  148. font-size: 16px;
  149. font-weight: bold;
  150. }
  151. </style>