Files
wer-admin/src/views/biz/help/index.vue
2026-11-05 09:27:00 +08:00

417 lines
14 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="p-2 page-shell helpManage-helpArticle-page">
<el-card shadow="hover" class="tabs-panel">
<div class="segmented" role="tablist" aria-label="帮助类型">
<button
v-for="tab in helpTabs"
:key="tab.value"
type="button"
role="tab"
class="segmented-item"
:class="{ 'is-active': activeTab === tab.value }"
:aria-selected="activeTab === tab.value"
@click="handleTabChange(tab.value)"
>
{{ tab.label }}
</button>
</div>
</el-card>
<div class="search-wrap">
<el-card shadow="hover" class="search-panel" :class="{ 'is-collapsed': !showSearch }">
<template #header>
<div class="panel-heading search-panel-toggle" @click.stop="showSearch = !showSearch">
<div><h3>筛选条件</h3></div>
</div>
</template>
<el-form ref="queryFormRef" :model="queryParams" :inline="true" class="query-form">
<el-form-item label="文章标题" prop="title">
<el-input v-model="queryParams.title" placeholder="请输入文章标题" clearable @keyup.enter="handleQuery" />
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable >
<el-option
v-for="dict in ur_help_article_status"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
</el-card>
</div>
<el-card shadow="hover" class="table-panel">
<template #header>
<div class="toolbar-shell">
<div class="table-heading">
<h3>帮助文章列表</h3>
</div>
<div class="toolbar-actions">
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['helpManage:helpArticle:add']">新增</el-button>
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['helpManage:helpArticle:edit']">修改</el-button>
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['helpManage:helpArticle:remove']">删除</el-button>
<!-- <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['helpManage:helpArticle:export']">导出</el-button> -->
<right-toolbar v-model:show-search="showSearch" :search="false" @query-table="getList"></right-toolbar>
</div>
</div>
</template>
<el-table v-loading="loading" border class="data-table" :data="helpArticleList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="文章标题" align="center" prop="title" min-width="180" show-overflow-tooltip />
<el-table-column label="更新时间" align="center" prop="updateTime" width="180">
<template #default="scope">
<span>{{ parseTime(scope.row.updateTime) || '-' }}</span>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status" width="100">
<template #default="scope">
<dict-tag :options="ur_help_article_status" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="190">
<template #default="scope">
<div class="table-actions">
<el-button
link
:type="isPublished(scope.row) ? 'warning' : 'success'"
@click="handleToggleStatus(scope.row)"
v-hasPermi="['helpManage:helpArticle:edit']"
>
{{ isPublished(scope.row) ? '下架' : '上架' }}
</el-button>
<el-button link type="primary" @click="handleUpdate(scope.row)" v-hasPermi="['helpManage:helpArticle:edit']">修改</el-button>
<el-button link type="danger" @click="handleDelete(scope.row)" v-hasPermi="['helpManage:helpArticle:remove']">删除</el-button>
</div>
</template>
</el-table-column>
</el-table>
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
</el-card>
<!-- 添加或修改帮助文章对话框 -->
<el-dialog :title="dialog.title" v-model="dialog.visible" width="800px" append-to-body>
<el-form ref="helpArticleFormRef" :model="form" :rules="rules" label-width="80px">
<el-form-item label="文章标题" prop="title">
<el-input v-model="form.title" placeholder="请输入文章标题" />
</el-form-item>
<el-form-item label="文章内容" prop="content">
<editor v-model="form.content" :min-height="192"/>
</el-form-item>
<el-form-item label="立即上架">
<el-switch v-model="publishNow" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup name="HelpArticle" lang="ts">
import {
addHelpArticle,
changeHelpArticleStatus,
delHelpArticle,
getHelpArticle,
listHelpArticle,
updateHelpArticle
} from '@/api/helpArticle/index';
import { HelpArticleForm, HelpArticleQuery, HelpArticleVO } from '@/api/helpArticle/types';
import { useLoading } from '@/hooks/async/useLoading';
import { useFormDialog } from '@/hooks/dialog/useFormDialog';
import { useSearchReset } from '@/hooks/form/useSearchReset';
import { useSearchToggle } from '@/hooks/form/useSearchToggle';
import { useTableSelection } from '@/hooks/table/useTableSelection';
import { parseTime } from '@/utils/ruoyi';
import { useDict } from '@/utils/dict';
import modal from '@/plugins/modal';
import { download as requestDownload } from '@/utils/request';
/** 状态字典 */
const { ur_help_article_status } = toRefs<any>(useDict('ur_help_article_status'));
/** 适用端:0 租客(用户帮助) 1 房东(房东帮助) */
const helpTabs = [
{ label: '用户帮助', value: '0' },
{ label: '房东帮助', value: '1' }
];
const activeTab = ref('0');
/** 是否已上架(兼容后端返回字符串或数字) */
const isPublished = (row: Partial<HelpArticleVO>) => String(row.status ?? '') === '1';
const helpArticleList = ref<HelpArticleVO[]>([]);
const buttonLoading = ref(false);
const { loading, withLoading } = useLoading(true);
const { showSearch } = useSearchToggle();
const total = ref(0);
const queryFormRef = ref<ElFormInstance>();
const helpArticleFormRef = ref<ElFormInstance>();
const initFormData: HelpArticleForm = {
articleId: undefined,
categoryId: undefined,
audience: undefined,
title: undefined,
content: undefined,
status: undefined,
publishedAt: undefined,
createDept: undefined,
createBy: undefined,
createTime: undefined,
updateBy: undefined,
updateTime: undefined,
}
const data = reactive<PageData<HelpArticleForm, HelpArticleQuery>>({
form: { ...initFormData },
queryParams: {
pageNum: 1,
pageSize: 10,
// 适用端必传:0 租客 / 1 房东,与页签保持一致
audience: '0',
title: undefined,
status: undefined
},
rules: {
title: [
{ required: true, message: "文章标题不能为空", trigger: "blur" }
],
content: [
{ required: true, message: "文章内容不能为空", trigger: "blur" }
],
}
});
const { queryParams, form, rules } = toRefs(data);
/** 弹窗「立即上架」开关:开 → 状态置为已上架并记录上架时间;关 → 草稿(已下架保持原状态) */
const publishNow = ref(false);
const applyPublishState = () => {
if (publishNow.value) {
// 从未上架转为上架时,记录本次上架时间
if (form.value.status !== '1') {
form.value.publishedAt = parseTime(new Date()) ?? undefined;
}
form.value.status = '1';
} else if (form.value.status !== '2') {
form.value.status = '0';
}
};
const { ids, single, multiple, handleSelectionChange } = useTableSelection<HelpArticleVO>(item => item.articleId);
const { dialog, resetForm: reset, openDialog, showDialog, closeDialog } = useFormDialog({
form,
formRef: helpArticleFormRef,
initialFormData: initFormData
});
/** 查询帮助文章列表 */
const getList = async () => {
await withLoading(async () => {
const res = await listHelpArticle(queryParams.value);
helpArticleList.value = res.data?.rows;
total.value = res.data?.total;
});
};
/** 取消按钮 */
const cancel = () => {
reset();
closeDialog();
};
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNum = 1;
getList();
};
/** 用户帮助 / 房东帮助切换 */
const handleTabChange = (audience: string) => {
if (activeTab.value === audience) return;
activeTab.value = audience;
queryParams.value.audience = audience;
handleQuery();
};
const { resetQuery } = useSearchReset({
queryFormRef,
queryParams,
pageNumKey: 'pageNum',
pageSizeKey: 'pageSize',
initialPageSize: 10,
afterReset: () => {
handleQuery();
}
});
/** 新增按钮操作 */
const handleAdd = () => {
publishNow.value = false;
openDialog('添加帮助文章');
// 适用端不在弹窗里编辑,默认归属当前页签
form.value.audience = activeTab.value;
};
/** 修改按钮操作 */
const handleUpdate = async (row?: Partial<HelpArticleVO>) => {
reset();
const articleId = row?.articleId || ids.value[0];
const res = await getHelpArticle(articleId);
Object.assign(form.value, res.data);
publishNow.value = form.value.status === '1';
showDialog('修改帮助文章');
};
/** 提交按钮 */
const submitForm = () => {
helpArticleFormRef.value?.validate(async (valid: boolean) => {
if (valid) {
applyPublishState();
buttonLoading.value = true;
if (form.value.articleId) {
await updateHelpArticle(form.value).finally(() => (buttonLoading.value = false));
} else {
await addHelpArticle(form.value).finally(() => (buttonLoading.value = false));
}
modal.msgSuccess('操作成功');
closeDialog();
await getList();
}
});
};
/**
* 上架 / 下架:PUT /helpManage/helpArticle/status/{articleId}/{status}
* 已上架(1) → 下架(2);草稿(0) / 已下架(2) → 上架(1)
*/
const handleToggleStatus = async (row: Partial<HelpArticleVO>) => {
if (row.articleId == null) return;
const currentStatus = String(row.status ?? '');
const nextStatus = currentStatus === '1' ? '2' : '1';
const actionText = nextStatus === '1' ? '上架' : '下架';
try {
await modal.confirm(`是否确认${actionText}文章"${row.title || row.articleId}"?`);
} catch {
// 用户取消确认
return;
}
await changeHelpArticleStatus(row.articleId, nextStatus);
modal.msgSuccess(`${actionText}成功`);
await getList();
};
/** 删除按钮操作 */
const handleDelete = async (row?: Partial<HelpArticleVO>) => {
const articleIds = row?.articleId || ids.value;
await modal.confirm('是否确认删除帮助文章编号为"' + articleIds + '"的数据项?');
await delHelpArticle(articleIds);
modal.msgSuccess('删除成功');
await getList();
};
/** 导出按钮操作 */
const handleExport = () => {
requestDownload(
'helpManage/helpArticle/export',
{
...queryParams.value
},
`helpArticle_${new Date().getTime()}.xlsx`
);
};
onMounted(() => {
getList();
});
</script>
<style scoped lang="scss">
/*
* 全局 _search-panel.scss 给 .data-table 里的 link 按钮加了 28x28 的圆角底色(带 !important),
* 操作列是纯文字按钮,这里用同等优先级覆盖掉底色与固定尺寸
*/
.data-table {
:deep(.table-actions) {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 4px 10px;
}
:deep(.table-actions .el-button.is-link) {
width: auto !important;
min-width: auto !important;
height: auto !important;
padding: 0 !important;
border-radius: 0 !important;
background: transparent !important;
font-size: 13px;
font-weight: 500;
}
:deep(.table-actions .el-button.is-link + .el-button.is-link) {
margin-left: 0 !important;
}
}
.tabs-panel {
:deep(.el-card__body) {
padding: 10px 16px;
}
}
/* 分段式切换:整条灰底,选中项为白色圆角浮起 */
.segmented {
display: flex;
gap: 4px;
padding: 4px;
border-radius: 10px;
background: var(--el-fill-color-light);
}
.segmented-item {
flex: 1;
padding: 8px 0;
border: 0;
border-radius: 8px;
background: transparent;
color: var(--el-text-color-secondary);
font-size: 14px;
line-height: 22px;
cursor: pointer;
transition:
background-color 0.2s,
color 0.2s;
&:hover {
color: var(--el-text-color-primary);
}
&.is-active {
background: var(--el-color-primary);
color: #fff;
// background: var(--app-surface-bg);
// color: var(--el-text-color-primary);
font-weight: 600;
box-shadow: 0 1px 3px rgb(0 0 0 / 8%);
}
}
</style>