index.vue 6.5 KB

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