index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <div class="search-nav-page">
  3. <div class="search-nav-container">
  4. <!-- 表格区域 -->
  5. <div class="table-card">
  6. <div class="table-header">
  7. <span class="table-title">搜索导航信息列表</span>
  8. <div class="table-header-right">
  9. <el-button type="primary" icon="Plus" @click="handleAdd">新增</el-button>
  10. <el-button icon="Refresh" circle size="small" @click="getList" />
  11. </div>
  12. </div>
  13. <el-table v-loading="loading" :data="navList" border>
  14. <el-table-column label="导航标题" align="center" prop="title" min-width="120" />
  15. <el-table-column label="链接地址" align="center" prop="link" min-width="280">
  16. <template #default="scope">
  17. <el-link type="primary" :href="scope.row.link" target="_blank">{{ scope.row.link }}</el-link>
  18. </template>
  19. </el-table-column>
  20. <el-table-column label="排序" align="center" prop="sort" width="100" />
  21. <el-table-column label="导航类型" align="center" width="120">
  22. <template #default>搜索导航</template>
  23. </el-table-column>
  24. <el-table-column label="操作" align="center" width="150">
  25. <template #default="scope">
  26. <span class="action-link danger" @click="handleDelete(scope.row)">删除</span>
  27. <span class="action-link primary" @click="handleEdit(scope.row)">编辑</span>
  28. </template>
  29. </el-table-column>
  30. </el-table>
  31. <pagination
  32. v-show="total > 0"
  33. v-model:page="queryParams.pageNum"
  34. v-model:limit="queryParams.pageSize"
  35. :total="total"
  36. @pagination="getList"
  37. />
  38. </div>
  39. </div>
  40. <!-- 添加/编辑对话框 -->
  41. <el-dialog v-model="dialog.visible" :title="dialog.title" width="500px" append-to-body>
  42. <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
  43. <el-form-item label="导航标题" prop="title">
  44. <el-input v-model="form.title" placeholder="请输入导航标题" />
  45. </el-form-item>
  46. <el-form-item label="链接地址" prop="link">
  47. <el-input v-model="form.link" placeholder="请输入链接地址" />
  48. </el-form-item>
  49. <el-form-item label="排序" prop="sort">
  50. <el-input-number v-model="form.sort" :min="0" :max="999" controls-position="right" />
  51. </el-form-item>
  52. </el-form>
  53. <template #footer>
  54. <el-button @click="dialog.visible = false">取 消</el-button>
  55. <el-button type="primary" @click="submitForm">确 定</el-button>
  56. </template>
  57. </el-dialog>
  58. </div>
  59. </template>
  60. <script setup name="IndustrialSearchNav" lang="ts">
  61. import { ref, reactive, onMounted } from 'vue';
  62. import { ElMessage, ElMessageBox } from 'element-plus';
  63. import { listIndustrialHomeTitle, addIndustrialHomeTitle, updateIndustrialHomeTitle, delIndustrialHomeTitle } from '@/api/system/industrialHomeTitle';
  64. // 固定的导航类型:0=搜索导航
  65. const NAV_TYPE = 0;
  66. // 查询参数
  67. const queryParams = reactive({
  68. pageNum: 1,
  69. pageSize: 10
  70. });
  71. // 列表数据
  72. const navList = ref<any[]>([]);
  73. const loading = ref(false);
  74. const total = ref(0);
  75. // 对话框
  76. const dialog = reactive({
  77. visible: false,
  78. title: ''
  79. });
  80. // 表单
  81. const formRef = ref();
  82. const initForm = {
  83. id: undefined as number | undefined,
  84. title: '',
  85. link: '',
  86. type: NAV_TYPE,
  87. sort: 0
  88. };
  89. const form = ref({ ...initForm });
  90. const rules = {
  91. title: [{ required: true, message: '请输入导航标题', trigger: 'blur' }],
  92. link: [{ required: true, message: '请输入链接地址', trigger: 'blur' }]
  93. };
  94. // 查询列表
  95. const getList = async () => {
  96. loading.value = true;
  97. try {
  98. const res: any = await listIndustrialHomeTitle({
  99. type: NAV_TYPE,
  100. pageNum: queryParams.pageNum,
  101. pageSize: queryParams.pageSize
  102. });
  103. navList.value = res.rows || [];
  104. total.value = res.total || 0;
  105. } catch (error) {
  106. console.error('加载列表失败', error);
  107. navList.value = [];
  108. total.value = 0;
  109. } finally {
  110. loading.value = false;
  111. }
  112. };
  113. // 添加
  114. const handleAdd = () => {
  115. form.value = { ...initForm };
  116. dialog.title = '新增导航';
  117. dialog.visible = true;
  118. };
  119. // 编辑
  120. const handleEdit = (row: any) => {
  121. form.value = {
  122. id: row.id,
  123. title: row.title || '',
  124. link: row.link || '',
  125. type: NAV_TYPE,
  126. sort: row.sort || 0
  127. };
  128. dialog.title = '编辑导航';
  129. dialog.visible = true;
  130. };
  131. // 删除
  132. const handleDelete = (row: any) => {
  133. ElMessageBox.confirm(`是否确认删除导航"${row.title}"?`, '提示', {
  134. confirmButtonText: '确定',
  135. cancelButtonText: '取消',
  136. type: 'warning'
  137. }).then(async () => {
  138. await delIndustrialHomeTitle(row.id);
  139. ElMessage.success('删除成功');
  140. getList();
  141. }).catch(() => {});
  142. };
  143. // 提交表单
  144. const submitForm = () => {
  145. formRef.value?.validate(async (valid: boolean) => {
  146. if (valid) {
  147. try {
  148. if (form.value.id) {
  149. await updateIndustrialHomeTitle(form.value);
  150. ElMessage.success('修改成功');
  151. } else {
  152. await addIndustrialHomeTitle(form.value);
  153. ElMessage.success('添加成功');
  154. }
  155. dialog.visible = false;
  156. getList();
  157. } catch (error) {
  158. ElMessage.error('操作失败');
  159. }
  160. }
  161. });
  162. };
  163. onMounted(() => {
  164. getList();
  165. });
  166. </script>
  167. <style scoped lang="scss">
  168. .search-nav-page {
  169. min-height: 100vh;
  170. background: #f5f5f5;
  171. padding: 20px;
  172. }
  173. .search-nav-container {
  174. max-width: 1200px;
  175. margin: 0 auto;
  176. }
  177. .table-card {
  178. background: #fff;
  179. border-radius: 4px;
  180. padding: 20px;
  181. }
  182. .table-header {
  183. display: flex;
  184. justify-content: space-between;
  185. align-items: center;
  186. margin-bottom: 15px;
  187. }
  188. .table-header-right {
  189. display: flex;
  190. align-items: center;
  191. gap: 10px;
  192. }
  193. .table-title {
  194. font-size: 16px;
  195. font-weight: 600;
  196. color: #303133;
  197. }
  198. .action-link {
  199. cursor: pointer;
  200. margin: 0 6px;
  201. &.primary {
  202. color: #409eff;
  203. &:hover { color: #66b1ff; }
  204. }
  205. &.danger {
  206. color: #f56c6c;
  207. &:hover { color: #f78989; }
  208. }
  209. }
  210. </style>