Files
admin-ui/src/views/customerService/script/index.vue

289 lines
7.2 KiB
Vue
Raw Normal View History

2025-11-22 16:39:01 +08:00
<template>
2025-11-24 16:55:18 +08:00
<div class="system-role-container">
<el-card shadow="hover">
2025-11-27 15:37:13 +08:00
<!-- 搜索和操作区域 -->
2025-11-24 16:55:18 +08:00
<div class="system-user-search mb15">
<el-form :inline="true">
2025-12-04 16:26:26 +08:00
<el-form-item label="标签">
<el-input size="default" v-model="tableData.param.tag" placeholder="请输入标签" class="w-50 m-2" clearable @keyup.enter="handleSearch" />
</el-form-item>
2025-11-24 16:55:18 +08:00
<el-form-item>
2025-12-04 16:26:26 +08:00
<el-button size="default" type="primary" class="ml10" @click="handleSearch" :loading="tableData.loading">
<el-icon>
<ele-Search />
</el-icon>
查询
</el-button>
<el-button size="default" class="ml10" @click="handleReset" :disabled="tableData.loading">
<el-icon>
<ele-Refresh />
</el-icon>
重置
</el-button>
<el-button size="default" type="success" class="op-btn-add" @click="handleAdd">
2025-11-27 15:37:13 +08:00
<el-icon><FolderAdd /></el-icon>
2025-11-24 16:55:18 +08:00
新增话术
</el-button>
</el-form-item>
</el-form>
</div>
2025-11-27 15:37:13 +08:00
<!-- 数据表格 -->
<el-table :data="tableData.data" v-loading="tableData.loading" style="width: 100%">
<el-table-column type="index" label="序号" width="60" align="center" />
<el-table-column prop="tag" label="标签" show-overflow-tooltip min-width="120" />
<el-table-column prop="creator" label="创建人" show-overflow-tooltip min-width="100" />
2025-12-02 17:05:20 +08:00
<el-table-column prop="updater" label="修改人" show-overflow-tooltip min-width="100" />
2025-11-28 17:17:07 +08:00
<el-table-column prop="createdAt" label="创建时间" show-overflow-tooltip min-width="140">
<template #default="{ row }">
{{ formatTime(row.createdAt) }}
</template>
</el-table-column>
<el-table-column prop="updatedAt" label="修改时间" show-overflow-tooltip min-width="140">
<template #default="{ row }">
{{ formatTime(row.updatedAt) }}
</template>
</el-table-column>
2025-11-27 15:37:13 +08:00
<el-table-column label="操作" width="200" align="center" fixed="right">
<template #default="{ row }">
<el-button size="small" text type="primary" class="op-btn-edit" @click="handleEdit(row)">
2025-11-27 15:37:13 +08:00
<el-icon><EditPen /></el-icon>修改
</el-button>
<el-button size="small" text type="danger" class="op-btn-del" @click="handleDelete(row)">
2025-11-27 15:37:13 +08:00
<el-icon><DeleteFilled /></el-icon>删除
</el-button>
2025-11-24 16:55:18 +08:00
</template>
</el-table-column>
</el-table>
2025-11-27 15:37:13 +08:00
<!-- 分页组件 -->
2025-11-24 16:55:18 +08:00
<pagination
2025-11-27 15:37:13 +08:00
v-if="tableData.total > 0"
2025-11-24 16:55:18 +08:00
:total="tableData.total"
v-model:page="tableData.param.pageNum"
v-model:limit="tableData.param.pageSize"
2025-11-27 15:37:13 +08:00
@pagination="loadTableData"
2025-11-24 16:55:18 +08:00
/>
</el-card>
2025-11-27 15:37:13 +08:00
<!-- 编辑组件 -->
2025-12-05 15:45:14 +08:00
<EditRole ref="editRoleRef" @refresh="loadTableData" />
2025-11-24 16:55:18 +08:00
</div>
2025-11-22 16:39:01 +08:00
</template>
2025-11-27 15:37:13 +08:00
<script setup lang="ts">
2025-11-28 17:17:07 +08:00
import { reactive, ref, onMounted } from 'vue';
2025-11-22 16:39:01 +08:00
import { ElMessageBox, ElMessage } from 'element-plus';
2025-11-27 15:37:13 +08:00
import { FolderAdd, EditPen, DeleteFilled } from '@element-plus/icons-vue';
import EditRole from './component/editRole.vue';
import Pagination from '/@/components/pagination/index.vue';
2025-12-05 15:45:14 +08:00
import { getscriptList, deleteScript } from '/@/api/customerService/script';
2025-11-27 15:37:13 +08:00
// ==================== 类型定义 ====================
interface ScriptItem {
id: string;
tag: string;
creator: string;
modifier: string;
2025-11-28 17:17:07 +08:00
createdAt: string; // 保持原字段不变
updatedAt: string; // 保持原字段不变
2025-11-27 15:37:13 +08:00
content?: string;
}
interface TableParams {
pageNum: number;
pageSize: number;
2025-12-04 16:26:26 +08:00
tag: '';
2025-11-22 16:39:01 +08:00
}
2025-11-27 15:37:13 +08:00
interface TableState {
data: ScriptItem[];
2025-11-24 16:55:18 +08:00
total: number;
loading: boolean;
2025-11-27 15:37:13 +08:00
param: TableParams;
2025-11-22 16:39:01 +08:00
}
2025-11-27 15:37:13 +08:00
// ==================== 响应式数据 ====================
const editRoleRef = ref<InstanceType<typeof EditRole>>();
const tableData = reactive<TableState>({
2025-11-24 16:55:18 +08:00
data: [],
total: 0,
loading: false,
param: {
pageNum: 1,
pageSize: 10,
2025-12-04 16:26:26 +08:00
tag: '',
2025-11-24 16:55:18 +08:00
},
});
2025-11-27 15:37:13 +08:00
2025-12-04 16:26:26 +08:00
/**
* 处理搜索
*/
const handleSearch = () => {
tableData.param.pageNum = 1; // 搜索时重置到第一页
loadTableData();
};
/**
* 重置查询条件
*/
const handleReset = () => {
// 重新获取数据
tableData.param = { pageNum: 1, pageSize: 10, tag: '' };
loadTableData();
};
2025-11-28 17:17:07 +08:00
// ==================== 时间处理函数 ====================
/**
* 格式化时间显示
* @param time 时间字符串或时间戳
* @returns 格式化后的时间字符串
*/
2025-12-01 16:30:31 +08:00
const formatTime = (time: string | number | Date): string => {
2025-11-28 17:17:07 +08:00
if (!time) return '-';
try {
2025-12-01 16:30:31 +08:00
let date: Date;
if (time instanceof Date) {
date = time;
} else if (typeof time === 'string') {
// 直接使用字符串创建Date对象ISO格式会自动识别
date = new Date(time);
} else {
// 处理时间戳
let timestamp = time;
if (timestamp > 1000000000000) {
// 已经是毫秒时间戳
} else if (timestamp > 1000000000) {
// 秒时间戳,转换为毫秒
timestamp = timestamp * 1000;
}
date = new Date(timestamp);
2025-11-28 17:17:07 +08:00
}
if (isNaN(date.getTime())) {
2025-12-01 16:30:31 +08:00
return String(time);
2025-11-28 17:17:07 +08:00
}
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
} catch (error) {
console.error('时间格式化错误:', error);
2025-12-01 16:30:31 +08:00
return String(time);
2025-11-28 17:17:07 +08:00
}
};
2025-11-27 15:37:13 +08:00
// ==================== 方法定义 ====================
/**
* 加载表格数据
*/
const loadTableData = async () => {
try {
tableData.loading = true;
const response = await getscriptList(tableData.param);
const { list = [], total = 0 } = response.data || {};
tableData.data = list;
tableData.total = total;
} catch (error) {
console.error('加载数据失败:', error);
ElMessage.error('数据加载失败');
tableData.data = [];
tableData.total = 0;
} finally {
tableData.loading = false;
}
2025-11-24 16:55:18 +08:00
};
2025-11-27 15:37:13 +08:00
/**
* 新增话术
*/
const handleAdd = () => {
editRoleRef.value?.openDialog();
2025-11-24 16:55:18 +08:00
};
2025-11-27 15:37:13 +08:00
/**
* 编辑话术
*/
const handleEdit = (row: ScriptItem) => {
editRoleRef.value?.openDialog(row as any);
2025-11-24 16:55:18 +08:00
};
2025-11-27 15:37:13 +08:00
/**
* 删除话术
*/
const handleDelete = async (row: ScriptItem) => {
try {
await ElMessageBox.confirm(`确定要删除话术「${row.tag}」吗?此操作不可恢复。`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
});
2025-11-28 17:17:07 +08:00
2025-12-05 15:45:14 +08:00
await deleteScript({ id: row.id });
2025-11-27 15:37:13 +08:00
ElMessage.success('删除成功');
// 重新加载数据
await loadTableData();
} catch (error) {
if (error !== 'cancel') {
console.error('删除失败:', error);
ElMessage.error('删除失败');
}
}
2025-11-24 16:55:18 +08:00
};
2025-11-22 16:39:01 +08:00
2025-11-27 15:37:13 +08:00
/**
* 操作成功回调
*/
const handleSuccess = () => {
loadTableData();
2025-11-24 16:55:18 +08:00
};
2025-11-27 15:37:13 +08:00
// ==================== 生命周期 ====================
2025-11-24 16:55:18 +08:00
onMounted(() => {
2025-11-27 15:37:13 +08:00
loadTableData();
});
// ==================== 暴露方法(可选) ====================
defineExpose({
reload: loadTableData,
2025-11-22 16:39:01 +08:00
});
</script>
2025-11-27 15:37:13 +08:00
<style scoped lang="scss">
.system-role-container {
.system-user-search {
display: flex;
justify-content: space-between;
align-items: center;
}
.mb15 {
margin-bottom: 15px;
}
}
// 响应式适配
@media (max-width: 768px) {
.system-user-search {
flex-direction: column;
align-items: flex-start;
.el-form-item {
margin-bottom: 10px;
}
}
}
</style>