| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <template>
- <div class="search-nav-page">
- <div class="search-nav-container">
- <!-- 表格区域 -->
- <div class="table-card">
- <div class="table-header">
- <span class="table-title">搜索导航信息列表</span>
- <div class="table-header-right">
- <el-button type="primary" icon="Plus" @click="handleAdd">新增</el-button>
- <el-button icon="Refresh" circle size="small" @click="getList" />
- </div>
- </div>
- <el-table v-loading="loading" :data="navList" border>
- <el-table-column label="导航标题" align="center" prop="title" min-width="120" />
- <el-table-column label="链接地址" align="center" prop="link" min-width="280">
- <template #default="scope">
- <el-link type="primary" :href="scope.row.link" target="_blank">{{ scope.row.link }}</el-link>
- </template>
- </el-table-column>
- <el-table-column label="排序" align="center" prop="sort" width="100" />
- <el-table-column label="导航类型" align="center" width="120">
- <template #default>搜索导航</template>
- </el-table-column>
- <el-table-column label="操作" align="center" width="150">
- <template #default="scope">
- <span class="action-link danger" @click="handleDelete(scope.row)">删除</span>
- <span class="action-link primary" @click="handleEdit(scope.row)">编辑</span>
- </template>
- </el-table-column>
- </el-table>
- <pagination
- v-show="total > 0"
- v-model:page="queryParams.pageNum"
- v-model:limit="queryParams.pageSize"
- :total="total"
- @pagination="getList"
- />
- </div>
- </div>
- <!-- 添加/编辑对话框 -->
- <el-dialog v-model="dialog.visible" :title="dialog.title" width="500px" append-to-body>
- <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
- <el-form-item label="导航标题" prop="title">
- <el-input v-model="form.title" placeholder="请输入导航标题" />
- </el-form-item>
- <el-form-item label="链接地址" prop="link">
- <el-input v-model="form.link" placeholder="请输入链接地址" />
- </el-form-item>
- <el-form-item label="排序" prop="sort">
- <el-input-number v-model="form.sort" :min="0" :max="999" controls-position="right" />
- </el-form-item>
- </el-form>
- <template #footer>
- <el-button @click="dialog.visible = false">取 消</el-button>
- <el-button type="primary" @click="submitForm">确 定</el-button>
- </template>
- </el-dialog>
- </div>
- </template>
- <script setup name="IndustrialSearchNav" lang="ts">
- import { ref, reactive, onMounted } from 'vue';
- import { ElMessage, ElMessageBox } from 'element-plus';
- import { listIndustrialHomeTitle, addIndustrialHomeTitle, updateIndustrialHomeTitle, delIndustrialHomeTitle } from '@/api/system/industrialHomeTitle';
- // 固定的导航类型:0=搜索导航
- const NAV_TYPE = 0;
- // 查询参数
- const queryParams = reactive({
- pageNum: 1,
- pageSize: 10
- });
- // 列表数据
- const navList = ref<any[]>([]);
- const loading = ref(false);
- const total = ref(0);
- // 对话框
- const dialog = reactive({
- visible: false,
- title: ''
- });
- // 表单
- const formRef = ref();
- const initForm = {
- id: undefined as number | undefined,
- title: '',
- link: '',
- type: NAV_TYPE,
- sort: 0
- };
- const form = ref({ ...initForm });
- const rules = {
- title: [{ required: true, message: '请输入导航标题', trigger: 'blur' }],
- link: [{ required: true, message: '请输入链接地址', trigger: 'blur' }]
- };
- // 查询列表
- const getList = async () => {
- loading.value = true;
- try {
- const res: any = await listIndustrialHomeTitle({
- type: NAV_TYPE,
- pageNum: queryParams.pageNum,
- pageSize: queryParams.pageSize
- });
- navList.value = res.rows || [];
- total.value = res.total || 0;
- } catch (error) {
- console.error('加载列表失败', error);
- navList.value = [];
- total.value = 0;
- } finally {
- loading.value = false;
- }
- };
- // 添加
- const handleAdd = () => {
- form.value = { ...initForm };
- dialog.title = '新增导航';
- dialog.visible = true;
- };
- // 编辑
- const handleEdit = (row: any) => {
- form.value = {
- id: row.id,
- title: row.title || '',
- link: row.link || '',
- type: NAV_TYPE,
- sort: row.sort || 0
- };
- dialog.title = '编辑导航';
- dialog.visible = true;
- };
- // 删除
- const handleDelete = (row: any) => {
- ElMessageBox.confirm(`是否确认删除导航"${row.title}"?`, '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(async () => {
- await delIndustrialHomeTitle(row.id);
- ElMessage.success('删除成功');
- getList();
- }).catch(() => {});
- };
- // 提交表单
- const submitForm = () => {
- formRef.value?.validate(async (valid: boolean) => {
- if (valid) {
- try {
- if (form.value.id) {
- await updateIndustrialHomeTitle(form.value);
- ElMessage.success('修改成功');
- } else {
- await addIndustrialHomeTitle(form.value);
- ElMessage.success('添加成功');
- }
- dialog.visible = false;
- getList();
- } catch (error) {
- ElMessage.error('操作失败');
- }
- }
- });
- };
- onMounted(() => {
- getList();
- });
- </script>
- <style scoped lang="scss">
- .search-nav-page {
- min-height: 100vh;
- background: #f5f5f5;
- padding: 20px;
- }
- .search-nav-container {
- max-width: 1200px;
- margin: 0 auto;
- }
- .table-card {
- background: #fff;
- border-radius: 4px;
- padding: 20px;
- }
- .table-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 15px;
- }
- .table-header-right {
- display: flex;
- align-items: center;
- gap: 10px;
- }
- .table-title {
- font-size: 16px;
- font-weight: 600;
- color: #303133;
- }
- .action-link {
- cursor: pointer;
- margin: 0 6px;
-
- &.primary {
- color: #409eff;
- &:hover { color: #66b1ff; }
- }
-
- &.danger {
- color: #f56c6c;
- &:hover { color: #f78989; }
- }
- }
- </style>
|