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

248 lines
6.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">
<el-form-item>
2025-11-27 15:37:13 +08:00
<el-button size="default" type="success" @click="handleAdd">
<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" />
<el-table-column prop="modifier" 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 }">
2025-11-28 17:17:07 +08:00
<el-button style="color: deepskyblue" size="small" text type="primary" @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" @click="handleDelete(row)">
<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
<!-- 编辑组件 -->
<EditRole ref="editRoleRef" @success="handleSuccess" />
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';
import { getscriptList, deletescript } from '/@/api/customerService/script';
// ==================== 类型定义 ====================
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-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-11-27 15:37:13 +08:00
2025-11-28 17:17:07 +08:00
// ==================== 时间处理函数 ====================
/**
* 格式化时间显示
* @param time 时间字符串或时间戳
* @returns 格式化后的时间字符串
*/
const formatTime = (time: string | number): string => {
if (!time) return '-';
try {
// 如果是时间戳格式
let timestamp = typeof time === 'string' ? parseInt(time) : time;
// 如果是毫秒时间戳,需要判断是否需要转换
if (timestamp > 1000000000000) {
// 已经是毫秒时间戳
} else if (timestamp > 1000000000) {
// 秒时间戳,转换为毫秒
timestamp = timestamp * 1000;
}
const date = new Date(timestamp);
if (isNaN(date.getTime())) {
return String(time); // 返回原始值
}
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);
return String(time); // 返回原始值
}
};
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);
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
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>