update:统一接口读取方式

This commit is contained in:
hrz
2025-04-05 21:03:46 +08:00
parent 03441c8582
commit fe86e1fb0f
15 changed files with 304 additions and 461 deletions
+9
View File
@@ -1,5 +1,10 @@
// 引入各个模块的请求
import admin from './module/admin.js'
import agent from './module/agent.js'
import device from './module/device.js'
import model from './module/model.js'
import user from './module/user.js'
/**
* 接口地址
* 开发时自动读取使用.env.development文件
@@ -20,4 +25,8 @@ export function getServiceUrl() {
export default {
getServiceUrl,
user,
admin,
agent,
device,
model,
}
-2
View File
@@ -100,7 +100,6 @@ function sendRequest() {
*/
// 在错误处理函数中添加日志
function httpHandlerError(info, callBack) {
console.log('httpHandlerError', info)
/** 请求成功,退出该函数 可以根据项目需求来判断是否请求成功。这里判断的是status为200的时候是成功 */
let networkError = false
@@ -108,7 +107,6 @@ function httpHandlerError(info, callBack) {
if (info.data.code === 'success' || info.data.code === 0 || info.data.code === undefined) {
return networkError
} else if (info.data.code === 401) {
console.log('触发 401,清除 Token 并跳转登录页');
store.commit('clearAuth');
goToPage(Constant.PAGE.LOGIN, true);
return true
-54
View File
@@ -1,54 +0,0 @@
import { getServiceUrl } from '../api'
import RequestService from '../httpRequest'
export default {
/**
* 设备激活接口
* @param {string} code 激活码
* @param {function} callback 回调函数
*/
activateDevice(code, callback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/api/v1/ota/activation`)
.method('GET')
.query({ code })
.success((res) => {
RequestService.clearRequestTime()
callback(res)
})
.fail((err) => {
console.error('设备激活失败:', err)
RequestService.reAjaxFun(() => {
this.activateDevice(code, callback)
})
}).send()
},
/**
* 检查OTA版本和设备激活状态
* @param {object} deviceInfo 设备信息对象
* @param {string} deviceId 设备唯一标识
* @param {string} clientId 客户端标识
* @param {function} callback 回调函数
*/
checkOtaVersion(deviceInfo, deviceId, clientId, callback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/api/v1/ota`)
.method('POST')
.header({
'Device-Id': deviceId,
'Client-Id': clientId
})
.data(deviceInfo)
.success((res) => {
RequestService.clearRequestTime()
callback(res)
})
.fail((err) => {
console.error('检查OTA版本失败:', err)
RequestService.reAjaxFun(() => {
this.checkOtaVersion(deviceInfo, deviceId, clientId, callback)
})
}).send()
}
}
@@ -1,98 +0,0 @@
<template>
<el-dialog :visible.sync="visible" width="400px" center>
<div style="margin: 0 10px 10px;display: flex;align-items: center;gap: 10px;font-weight: 700;font-size: 20px;text-align: left;color: #3d4566;">
<div style="width: 40px;height: 40px;border-radius: 50%;background: #5778ff;display: flex;align-items: center;justify-content: center;">
<img src="@/assets/home/equipment.png" alt="" style="width: 18px;height: 15px;" />
</div>
激活设备
</div>
<div style="height: 1px;background: #e8f0ff;" />
<div style="margin: 22px 15px;">
<div style="font-weight: 400;font-size: 14px;text-align: left;color: #3d4566;">
<div style="color: red;display: inline-block;">*</div> 设备激活码
</div>
<div class="input-46" style="margin-top: 12px;">
<el-input placeholder="请输入设备播报的激活码.." v-model="activateCode" />
</div>
</div>
<div style="display: flex;margin: 15px 15px;gap: 7px;">
<div class="dialog-btn" @click="confirm">
确定
</div>
<div class="dialog-btn"
style="background: #e6ebff;border: 1px solid #adbdff;color: #5778ff;"
@click="cancel">
取消
</div>
</div>
</el-dialog>
</template>
<script>
import userApi from '@/apis/module/user';
export default {
name: 'ActivateDeviceDialog',
props: {
visible: { type: Boolean, required: true }
},
data() {
return { activateCode: "" }
},
methods: {
confirm() {
if (!this.activateCode.trim()) {
this.$message.error('请输入激活码');
return;
}
userApi.activateDevice(this.activateCode, (res) => {
this.$message.success('激活成功,请重新唤醒设备即可完成激活!');
this.$emit('confirm', res);
this.$emit('update:visible', false);
console.log("res: ", res)
this.activateCode = "";
});
},
cancel() {
this.$emit('update:visible', false)
this.activateCode = ""
}
}
}
</script>
<style scoped>
.input-46 {
border: 1px solid #e4e6ef;
background: #f6f8fb;
border-radius: 15px;
}
.dialog-btn {
cursor: pointer;
flex: 1;
border-radius: 23px;
background: #5778ff;
height: 40px;
font-weight: 500;
font-size: 12px;
color: #fff;
line-height: 40px;
text-align: center;
}
::v-deep .el-dialog {
border-radius: 15px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
::v-deep .el-dialog__headerbtn {
display: none;
}
::v-deep .el-dialog__body {
padding: 4px 6px;
}
::v-deep .el-dialog__header{
padding: 10px;
}
</style>
@@ -1,7 +1,9 @@
<template>
<el-dialog :visible.sync="visible" width="400px" center >
<div style="margin: 0 10px 10px;display: flex;align-items: center;gap: 10px;font-weight: 700;font-size: 20px;text-align: left;color: #3d4566;">
<div style="width: 40px;height: 40px;border-radius: 50%;background: #5778ff;display: flex;align-items: center;justify-content: center;">
<el-dialog :visible.sync="visible" width="400px" center>
<div
style="margin: 0 10px 10px;display: flex;align-items: center;gap: 10px;font-weight: 700;font-size: 20px;text-align: left;color: #3d4566;">
<div
style="width: 40px;height: 40px;border-radius: 50%;background: #5778ff;display: flex;align-items: center;justify-content: center;">
<img src="@/assets/home/equipment.png" alt="" style="width: 18px;height: 15px;" />
</div>
添加设备
@@ -13,16 +15,14 @@
<span style="font-size: 11px"> 验证码</span>
</div>
<div class="input-46" style="margin-top: 12px;">
<el-input placeholder="请输入设备播报的6位数验证码.." v-model="deviceCode" @keyup.enter.native="confirm"/>
<el-input placeholder="请输入设备播报的6位数验证码.." v-model="deviceCode" @keyup.enter.native="confirm" />
</div>
</div>
<div style="display: flex;margin: 15px 15px;gap: 7px;">
<div class="dialog-btn" @click="confirm">
确定
</div>
<div class="dialog-btn"
style="background: #e6ebff;border: 1px solid #adbdff;color: #5778ff;"
@click="cancel">
<div class="dialog-btn" style="background: #e6ebff;border: 1px solid #adbdff;color: #5778ff;" @click="cancel">
取消
</div>
</div>
@@ -30,6 +30,8 @@
</template>
<script>
import Api from '@/apis/api';
export default {
name: 'AddDeviceDialog',
props: {
@@ -49,31 +51,25 @@ export default {
return;
}
this.loading = true;
import('@/apis/module/device').then(({ default: deviceApi }) => {
deviceApi.bindDevice(
this.agentId,
this.deviceCode, ({data}) => {
this.loading = false;
if (data.code === 0) {
this.$emit('refresh');
this.$message.success({
message: '设备绑定成功',
showClose: true
});
this.closeDialog();
} else {
this.$message.error({
message: data.msg || '绑定失败',
showClose: true
});
}
}
);
}).catch((err) => {
Api.device.bindDevice(
this.agentId,
this.deviceCode, ({ data }) => {
this.loading = false;
console.error('API模块加载失败:', err);
this.$message.error('绑定服务不可用');
});
if (data.code === 0) {
this.$emit('refresh');
this.$message.success({
message: '设备绑定成功',
showClose: true
});
this.closeDialog();
} else {
this.$message.error({
message: data.msg || '绑定失败',
showClose: true
});
}
}
);
},
closeDialog() {
this.$emit('update:visible', false);
@@ -89,7 +85,6 @@ export default {
</script>
<style scoped>
.input-46 {
border: 1px solid #e4e6ef;
background: #f6f8fb;
@@ -113,14 +108,16 @@ export default {
border-radius: 15px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
::v-deep .el-dialog__headerbtn {
display: none;
}
::v-deep .el-dialog__body {
padding: 4px 6px;
}
::v-deep .el-dialog__header{
::v-deep .el-dialog__header {
padding: 10px;
}
</style>
@@ -1,5 +1,6 @@
<template>
<el-dialog :visible.sync="visible" width="975px" center custom-class="custom-dialog" :show-close="false" class="center-dialog">
<el-dialog :visible.sync="visible" width="975px" center custom-class="custom-dialog" :show-close="false"
class="center-dialog">
<div style="margin: 0 18px; text-align: left; padding: 10px; border-radius: 10px;">
<div style="font-size: 30px; color: #3d4566; margin-top: -10px; margin-bottom: 10px; text-align: center;">
添加模型
@@ -38,8 +39,9 @@
<div style="display: flex; gap: 20px; margin-bottom: 0;">
<el-form-item label="供应器" prop="supplier" style="flex: 1;">
<el-select v-model="formData.supplier" placeholder="请选择" class="custom-select custom-input-bg" style="width: 100%;" @focus="loadProviders" filterable>
<el-option v-for="item in providers" :key="item.value" :label="item.label" :value="item.value"/>
<el-select v-model="formData.supplier" placeholder="请选择" class="custom-select custom-input-bg"
style="width: 100%;" @focus="loadProviders" filterable>
<el-option v-for="item in providers" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item label="排序号" prop="sortOrder" style="flex: 1;">
@@ -49,21 +51,12 @@
<el-form-item label="文档地址" prop="docLink" style="margin-bottom: 27px;">
<el-input
v-model="formData.docLink"
placeholder="请输入文档地址"
class="custom-input-bg"
></el-input>
<el-input v-model="formData.docLink" placeholder="请输入文档地址" class="custom-input-bg"></el-input>
</el-form-item>
<el-form-item label="备注" prop="remark" class="prop-remark">
<el-input
v-model="formData.remark"
type="textarea"
:rows="3"
placeholder="请输入模型备注"
class="custom-input-bg"
></el-input>
<el-input v-model="formData.remark" type="textarea" :rows="3" placeholder="请输入模型备注"
class="custom-input-bg"></el-input>
</el-form-item>
</el-form>
@@ -73,7 +66,8 @@
<el-form :model="formData" label-width="100px" label-position="left" class="custom-form">
<div style="display: flex; gap: 10px; margin-bottom: 15px;">
<el-form-item label="模型名称" prop="param1" style="flex: 0.5; margin-bottom: 0;">
<el-input v-model="formData.configJson.param1" placeholder="请输入model_name" class="custom-input-bg"></el-input>
<el-input v-model="formData.configJson.param1" placeholder="请输入model_name"
class="custom-input-bg"></el-input>
</el-form-item>
<el-form-item label="接口地址" prop="param2" style="flex: 1; margin-bottom: 0;">
<el-input v-model="formData.configJson.param2" placeholder="请输入base_url" class="custom-input-bg"></el-input>
@@ -81,7 +75,8 @@
</div>
<el-form-item label="秘钥信息" prop="apiKey">
<el-input v-model="formData.configJson.apiKey" placeholder="请输入api_key" show-password class="custom-input-bg"></el-input>
<el-input v-model="formData.configJson.apiKey" placeholder="请输入api_key" show-password
class="custom-input-bg"></el-input>
</el-form-item>
</el-form>
</div>
@@ -95,12 +90,12 @@
</template>
<script>
import model from '@/apis/module/model'
import Api from '@/apis/api';
export default {
name: 'AddModelDialog',
props: {
visible: {type: Boolean, required: true},
modelType: {type: String, required: true}
visible: { type: Boolean, required: true },
modelType: { type: String, required: true }
},
data() {
return {
@@ -128,7 +123,7 @@ export default {
if (this.providersLoaded)
return
model.getModelProviders(this.modelType, (data) => {
Api.model.getModelProviders(this.modelType, (data) => {
this.providers = data.map(item => ({
label: item.name,
value: item.providerCode
@@ -138,7 +133,7 @@ export default {
},
confirm() {
if (!this.formData.modelName || !this.formData.modelCode || !this.formData.supplier ||
!this.formData.configJson.param1 || !this.formData.configJson.param2 || !this.formData.configJson.apiKey) {
!this.formData.configJson.param1 || !this.formData.configJson.param2 || !this.formData.configJson.apiKey) {
this.$message.error('请填写所有必填字段');
return;
}
@@ -344,6 +339,4 @@ export default {
.custom-input-bg .el-input__inner {
height: 32px;
}
</style>
@@ -1,7 +1,9 @@
<template>
<el-dialog :visible.sync="visible" width="400px" center @open="handleOpen">
<div style="margin: 0 10px 10px;display: flex;align-items: center;gap: 10px;font-weight: 700;font-size: 20px;text-align: left;color: #3d4566;">
<div style="width: 40px;height: 40px;border-radius: 50%;background: #5778ff;display: flex;align-items: center;justify-content: center;">
<div
style="margin: 0 10px 10px;display: flex;align-items: center;gap: 10px;font-weight: 700;font-size: 20px;text-align: left;color: #3d4566;">
<div
style="width: 40px;height: 40px;border-radius: 50%;background: #5778ff;display: flex;align-items: center;justify-content: center;">
<img loading="lazy" src="@/assets/home/equipment.png" alt="" style="width: 18px;height: 15px;" />
</div>
添加智能体
@@ -12,20 +14,14 @@
<div style="color: red;display: inline-block;">*</div> 智慧体名称
</div>
<div class="input-46" style="margin-top: 12px;">
<el-input
ref="inputRef"
placeholder="请输入智能体名称.."
v-model="wisdomBodyName"
@keyup.enter.native="confirm" />
<el-input ref="inputRef" placeholder="请输入智能体名称.." v-model="wisdomBodyName" @keyup.enter.native="confirm" />
</div>
</div>
<div style="display: flex;margin: 15px 15px;gap: 7px;">
<div class="dialog-btn" @click="confirm">
确定
</div>
<div class="dialog-btn"
style="background: #e6ebff;border: 1px solid #adbdff;color: #5778ff;"
@click="cancel">
<div class="dialog-btn" style="background: #e6ebff;border: 1px solid #adbdff;color: #5778ff;" @click="cancel">
取消
</div>
</div>
@@ -33,7 +29,7 @@
</template>
<script>
import userApi from '@/apis/module/agent';
import Api from '@/apis/api';
export default {
name: 'AddWisdomBodyDialog',
@@ -57,10 +53,10 @@ export default {
this.$message.error('请输入智能体名称');
return;
}
userApi.addAgent(this.wisdomBodyName, (res) => {
Api.agent.addAgent(this.wisdomBodyName, (res) => {
this.$message.success({
message: '添加成功',
showClose: true
message: '添加成功',
showClose: true
});
this.$emit('confirm', res);
this.$emit('update:visible', false);
@@ -94,17 +90,21 @@ export default {
line-height: 40px;
text-align: center;
}
::v-deep .el-dialog {
border-radius: 15px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
::v-deep .el-dialog__headerbtn {
display: none;
}
::v-deep .el-dialog__body {
padding: 4px 6px;
}
::v-deep .el-dialog__header{
::v-deep .el-dialog__header {
padding: 10px;
}
</style>
@@ -1,5 +1,6 @@
<template>
<el-dialog :visible.sync="dialogVisible" width="975px" center custom-class="custom-dialog" :show-close="false" class="center-dialog">
<el-dialog :visible.sync="dialogVisible" width="975px" center custom-class="custom-dialog" :show-close="false"
class="center-dialog">
<div style="margin: 0 18px; text-align: left; padding: 10px; border-radius: 10px;">
<div style="font-size: 30px; color: #3d4566; margin-top: -10px; margin-bottom: 10px; text-align: center;">
修改模型
@@ -37,9 +38,10 @@
<div style="display: flex; gap: 20px; margin-bottom: 0;">
<el-form-item label="供应器" prop="supplier" style="flex: 1;">
<el-select v-model="form.supplier" placeholder="请选择" class="custom-select custom-input-bg" style="width: 100%;" @focus="loadProviders" filterable>
<el-option v-for="item in providers" :key="item.value" :label="item.label" :value="item.value"/>
</el-select>
<el-select v-model="form.supplier" placeholder="请选择" class="custom-select custom-input-bg"
style="width: 100%;" @focus="loadProviders" filterable>
<el-option v-for="item in providers" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item label="排序号" prop="sort" style="flex: 1;">
<el-input v-model="form.sort" placeholder="请输入排序号" class="custom-input-bg"></el-input>
@@ -51,7 +53,8 @@
</el-form-item>
<el-form-item label="备注" prop="remark" class="prop-remark">
<el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请输入模型备注" class="custom-input-bg"></el-input>
<el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请输入模型备注"
class="custom-input-bg"></el-input>
</el-form-item>
</el-form>
@@ -83,7 +86,7 @@
</template>
<script>
import model from '@/apis/module/model'
import Api from '@/apis/api';
export default {
name: "ModelConfigDialog",
props: {
@@ -149,7 +152,7 @@ export default {
loadProviders() {
if (this.providersLoaded) return
model.getModelProviders(this.modelType, (data) => {
Api.model.getModelProviders(this.modelType, (data) => {
this.providers = data.map(item => ({
label: item.name,
value: item.providerCode
+32 -39
View File
@@ -53,6 +53,7 @@
</template>
<script>
import Api from '@/apis/api';
import AddDeviceDialog from "@/components/AddDeviceDialog.vue";
import HeaderBar from "@/components/HeaderBar.vue";
@@ -78,12 +79,9 @@ export default {
},
mounted() {
const agentId = this.$route.query.agentId;
import('@/apis/module/device').then(({ default: deviceApi }) => {
this.deviceApi = deviceApi;
if (agentId) {
this.fetchBindDevices(agentId);
}
});
if (agentId) {
this.fetchBindDevices(agentId);
}
},
methods: {
handleAddDevice() {
@@ -105,7 +103,7 @@ export default {
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.deviceApi.unbindDevice(device_id, ({ data }) => {
Api.device.unbindDevice(device_id, ({ data }) => {
if (data.code === 0) {
this.$message.success({
message: '设备解绑成功',
@@ -129,38 +127,33 @@ export default {
},
fetchBindDevices(agentId) {
this.loading = true;
import('@/apis/module/device').then(({ default: deviceApi }) => {
deviceApi.getAgentBindDevices(agentId, ({ data }) => {
this.loading = false;
if (data.code === 0) {
// 格式化日期并按照绑定时间降序排列
this.deviceList = data.data.map(device => {
// 格式化绑定时间
const bindDate = new Date(device.createDate);
const formattedBindTime = `${bindDate.getFullYear()}-${(bindDate.getMonth() + 1).toString().padStart(2, '0')}-${bindDate.getDate().toString().padStart(2, '0')} ${bindDate.getHours().toString().padStart(2, '0')}:${bindDate.getMinutes().toString().padStart(2, '0')}:${bindDate.getSeconds().toString().padStart(2, '0')}`;
return {
device_id: device.id,
model: device.board,
firmwareVersion: device.appVersion,
macAddress: device.macAddress,
bindTime: formattedBindTime, // 使用格式化后的时间
lastConversation: device.lastConnectedAt,
remark: device.alias,
isEdit: false,
otaSwitch: device.autoUpdate === 1,
// 添加原始时间用于排序
rawBindTime: new Date(device.createDate).getTime()
};
})
// 按照绑定时间降序排序
.sort((a, b) => a.rawBindTime - b.rawBindTime);
} else {
this.$message.error(data.msg || '获取设备列表失败');
}
});
}).catch(error => {
console.error('模块加载失败:', error);
this.$message.error('功能模块加载失败');
Api.device.getAgentBindDevices(agentId, ({ data }) => {
this.loading = false;
if (data.code === 0) {
// 格式化日期并按照绑定时间降序排列
this.deviceList = data.data.map(device => {
// 格式化绑定时间
const bindDate = new Date(device.createDate);
const formattedBindTime = `${bindDate.getFullYear()}-${(bindDate.getMonth() + 1).toString().padStart(2, '0')}-${bindDate.getDate().toString().padStart(2, '0')} ${bindDate.getHours().toString().padStart(2, '0')}:${bindDate.getMinutes().toString().padStart(2, '0')}:${bindDate.getSeconds().toString().padStart(2, '0')}`;
return {
device_id: device.id,
model: device.board,
firmwareVersion: device.appVersion,
macAddress: device.macAddress,
bindTime: formattedBindTime, // 使用格式化后的时间
lastConversation: device.lastConnectedAt,
remark: device.alias,
isEdit: false,
otaSwitch: device.autoUpdate === 1,
// 添加原始时间用于排序
rawBindTime: new Date(device.createDate).getTime()
};
})
// 按照绑定时间降序排序
.sort((a, b) => a.rawBindTime - b.rawBindTime);
} else {
this.$message.error(data.msg || '获取设备列表失败');
}
});
},
}
+10 -7
View File
@@ -101,7 +101,7 @@
<div class="batch-actions">
<el-button size="mini" @click="selectAll" style="width: 75px; background: #606ff3">{{ isAllSelected ?
'取消全选' : '全选'
}}</el-button>
}}</el-button>
<el-button size="mini" type="danger" icon="el-icon-delete" @click="batchDelete">
删除
</el-button>
@@ -135,7 +135,7 @@
</template>
<script>
import ModelApi from "@/apis/module/model";
import Api from "@/apis/api";
import AddModelDialog from "@/components/AddModelDialog.vue";
import HeaderBar from "@/components/HeaderBar.vue";
import ModelEditDialog from "@/components/ModelEditDialog.vue";
@@ -212,6 +212,7 @@ export default {
this.loadData();
},
handleSearch() {
// TODO: 查询
console.log('查询:', this.search);
},
// 批量删除
@@ -228,7 +229,7 @@ export default {
}).then(() => {
const deletePromises = this.selectedModels.map(model =>
new Promise(resolve => {
ModelApi.deleteModel(
Api.model.deleteModel(
this.activeTab,
model.configJson?.provider || '',
model.id,
@@ -263,7 +264,7 @@ export default {
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
ModelApi.deleteModel(
Api.model.deleteModel(
this.activeTab,
model.configJson?.provider || '', // 从configJson获取provider
model.id,
@@ -283,15 +284,17 @@ export default {
handleCurrentChange(page) {
this.currentPage = page;
this.$refs.modelTable.clearSelection();
console.log('当前页码:', page);
},
handleImport() {
// TODO: 导入配置
console.log('导入配置');
},
handleExport() {
// TODO: 导出配置
console.log('导出配置');
},
handleModelSave(formData) {
// TODO: 保存模型数据
console.log('保存的模型数据:', formData);
},
selectAll() {
@@ -321,7 +324,7 @@ export default {
}
};
ModelApi.addModel(params, ({ data }) => {
Api.model.addModel(params, ({ data }) => {
if (data.code === 0) {
this.$message.success('新增成功');
this.loadData();
@@ -362,7 +365,7 @@ export default {
limit: this.pageSize
};
ModelApi.getModelList(params, ({ data }) => {
Api.model.getModelList(params, ({ data }) => {
if (data.code === 0) {
this.modelList = data.data.list;
this.total = data.data.total;
+118 -108
View File
@@ -45,15 +45,20 @@
<el-button size="mini" type="danger" icon="el-icon-delete" @click="batchDelete">删除</el-button>
</div>
<div class="custom-pagination">
<button class="pagination-btn" :disabled="currentPage === 1" @click="goFirst">首页</button>
<button class="pagination-btn" :disabled="currentPage === 1" @click="goPrev">上一页</button>
<button class="pagination-btn" :disabled="currentPage === 1" @click="goFirst">
首页
</button>
<button class="pagination-btn" :disabled="currentPage === 1" @click="goPrev">
上一页
</button>
<button v-for="page in visiblePages" :key="page" class="pagination-btn"
:class="{ active: page === currentPage }" @click="goToPage(page)">
{{ page }}
</button>getUserList <button class="pagination-btn" :disabled="currentPage === pageCount"
@click="goNext">
下一页
</button>
<button class="pagination-btn" :disabled="currentPage === pageCount" @click="goNext">下一页</button>
<span class="total-text">{{ total }}条记录</span>
</div>
</div>
@@ -62,29 +67,27 @@
</div>
</div>
<div class="copyright">
©2025 xiaozhi-esp32-server
</div>
<div class="copyright">©2025 xiaozhi-esp32-server</div>
<view-password-dialog :visible.sync="showViewPassword" :password="currentPassword" />
</div>
</template>
<script>
import adminApi from '@/apis/module/admin';
import Api from "@/apis/api";
import HeaderBar from "@/components/HeaderBar.vue";
import ViewPasswordDialog from '@/components/ViewPasswordDialog.vue';
import ViewPasswordDialog from "@/components/ViewPasswordDialog.vue";
export default {
components: { HeaderBar, ViewPasswordDialog },
data() {
return {
showViewPassword: false,
currentPassword: '',
searchPhone: '',
currentPassword: "",
searchPhone: "",
userList: [],
currentPage: 1,
pageSize: 5,
total: 0
total: 0,
};
},
created() {
@@ -108,23 +111,26 @@ export default {
pages.push(i);
}
return pages;
}
},
},
methods: {
fetchUsers() {
adminApi.getUserList({
page: this.currentPage,
limit: this.pageSize,
mobile: this.searchPhone
}, ({ data }) => {
if (data.code === 0) {
this.userList = data.data.list.map(user => ({
...user,
status: user.status === '1' ? '正常' : '禁用'
}));
this.total = data.data.total;
Api.admin.getUserList(
{
page: this.currentPage,
limit: this.pageSize,
mobile: this.searchPhone,
},
({ data }) => {
if (data.code === 0) {
this.userList = data.data.list.map((user) => ({
...user,
status: user.status === "1" ? "正常" : "禁用",
}));
this.total = data.data.total;
}
}
});
);
},
handleSearch() {
this.currentPage = 1;
@@ -136,118 +142,122 @@ export default {
batchDelete() {
const selectedUsers = this.$refs.userTable.selection;
if (selectedUsers.length === 0) {
this.$message.warning('请先选择需要删除的用户');
this.$message.warning("请先选择需要删除的用户");
return;
}
this.$confirm(`确定要删除选中的${selectedUsers.length}个用户吗?`, '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
const loading = this.$loading({
lock: true,
text: '正在删除中...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
this.$confirm(`确定要删除选中的${selectedUsers.length}个用户吗?`, "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(async () => {
const loading = this.$loading({
lock: true,
text: "正在删除中...",
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.7)",
});
try {
const results = await Promise.all(
selectedUsers.map(user => {
return new Promise((resolve) => {
adminApi.deleteUser(user.userid, ({ data }) => {
if (data.code === 0) {
resolve({ success: true, userid: user.userid });
} else {
resolve({ success: false, userid: user.userid, msg: data.msg });
}
try {
const results = await Promise.all(
selectedUsers.map((user) => {
return new Promise((resolve) => {
Api.admin.deleteUser(user.userid, ({ data }) => {
if (data.code === 0) {
resolve({ success: true, userid: user.userid });
} else {
resolve({ success: false, userid: user.userid, msg: data.msg });
}
});
});
});
})
);
})
);
const successCount = results.filter(r => r.success).length;
const failCount = results.length - successCount;
const successCount = results.filter((r) => r.success).length;
const failCount = results.length - successCount;
if (failCount === 0) {
this.$message.success(`成功删除${successCount}个用户`);
} else if (successCount === 0) {
this.$message.error(`删除失败,请重试`);
} else {
this.$message.warning(`成功删除${successCount}个用户,${failCount}个删除失败`);
if (failCount === 0) {
this.$message.success(`成功删除${successCount}个用户`);
} else if (successCount === 0) {
this.$message.error(`删除失败,请重试`);
} else {
this.$message.warning(
`成功删除${successCount}个用户,${failCount}个删除失败`
);
}
this.fetchUsers();
} catch (error) {
this.$message.error("删除过程中发生错误");
} finally {
loading.close();
}
this.fetchUsers();
} catch (error) {
this.$message.error('删除过程中发生错误');
} finally {
loading.close();
}
}).catch(() => {
this.$message.info('已取消删除');
});
})
.catch(() => {
this.$message.info("已取消删除");
});
},
batchEnable() {
const selectedUsers = this.$refs.userTable.selection;
if (selectedUsers.length === 0) {
this.$message.warning('请先选择需要启用的用户');
this.$message.warning("请先选择需要启用的用户");
return;
}
selectedUsers.forEach(user => {
user.status = '正常';
selectedUsers.forEach((user) => {
user.status = "正常";
});
this.$message.success('启用操作成功');
this.$message.success("启用操作成功");
},
batchDisable() {
this.userList.forEach(user => {
user.status = '禁用';
this.userList.forEach((user) => {
user.status = "禁用";
});
this.$message.success('状态已更新为禁用');
this.$message.success("状态已更新为禁用");
},
resetPassword(row) {
this.$confirm('重置后将会生成新密码,是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消'
this.$confirm("重置后将会生成新密码,是否继续?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
}).then(() => {
adminApi.resetUserPassword(row.userid, ({ data }) => {
Api.admin.resetUserPassword(row.userid, ({ data }) => {
if (data.code === 0) {
this.currentPassword = data.data
this.showViewPassword = true
this.$message.success('密码已重置,请通知用户使用新密码登录')
this.currentPassword = data.data;
this.showViewPassword = true;
this.$message.success("密码已重置,请通知用户使用新密码登录");
}
})
})
});
});
},
disableUser(row) {
row.status = '禁用';
console.log('禁用用户:', row);
row.status = "禁用";
},
restoreUser(row) {
row.status = '正常';
console.log('恢复用户:', row);
row.status = "正常";
},
deleteUser(row) {
this.$confirm('确定要删除该用户吗?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
adminApi.deleteUser(row.userid, ({ data }) => {
if (data.code === 0) {
this.$message.success('删除成功')
this.fetchUsers()
} else {
this.$message.error(data.msg || '删除失败')
}
this.$confirm("确定要删除该用户吗?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
Api.admin.deleteUser(row.userid, ({ data }) => {
if (data.code === 0) {
this.$message.success("删除成功");
this.fetchUsers();
} else {
this.$message.error(data.msg || "删除失败");
}
});
})
}).catch(() => { })
.catch(() => { });
},
headerCellClassName({ columnIndex }) {
if (columnIndex === 0) {
return 'custom-selection-header'
return "custom-selection-header";
}
return ''
return "";
},
goFirst() {
this.currentPage = 1;
@@ -269,7 +279,7 @@ export default {
this.currentPage = page;
this.fetchUsers();
},
}
},
};
</script>
@@ -320,7 +330,7 @@ export default {
}
.btn-search {
background: linear-gradient(135deg, #6B8CFF, #A966FF);
background: linear-gradient(135deg, #6b8cff, #a966ff);
border: none;
color: white;
}
@@ -434,7 +444,7 @@ export default {
padding: 0 12px;
border-radius: 4px;
border: 1px solid #e4e7ed;
background: #DEE7FF;
background: #dee7ff;
color: #606266;
font-size: 14px;
cursor: pointer;
@@ -512,7 +522,7 @@ export default {
}
&::after {
content: '选择';
content: "选择";
display: inline-block;
color: black;
font-weight: bold;
@@ -555,4 +565,4 @@ export default {
}
}
}
</style>
</style>
+23 -27
View File
@@ -45,9 +45,10 @@
</template>
<script>
import AddWisdomBodyDialog from '@/components/AddWisdomBodyDialog.vue'
import DeviceItem from '@/components/DeviceItem.vue'
import HeaderBar from '@/components/HeaderBar.vue'
import Api from '@/apis/api';
import AddWisdomBodyDialog from '@/components/AddWisdomBodyDialog.vue';
import DeviceItem from '@/components/DeviceItem.vue';
import HeaderBar from '@/components/HeaderBar.vue';
export default {
name: 'HomePage',
@@ -75,7 +76,6 @@ export default {
this.$router.push('/role-config')
},
handleWisdomBodyAdded(res) {
console.log('新增智能体响应', res);
this.fetchAgentList();
this.addDeviceDialogVisible = false;
},
@@ -108,14 +108,12 @@ export default {
},
// 获取智能体列表
fetchAgentList() {
import('@/apis/module/agent').then(({ default: userApi }) => {
userApi.getAgentList(({ data }) => {
this.originalDevices = data.data.map(item => ({
...item,
agentId: item.id // 字段映射
}));
this.handleSearchReset(); // 重置搜索状态
});
Api.agent.getAgentList(({ data }) => {
this.originalDevices = data.data.map(item => ({
...item,
agentId: item.id // 字段映射
}));
this.handleSearchReset(); // 重置搜索状态
});
},
// 删除智能体
@@ -125,21 +123,19 @@ export default {
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
import('@/apis/module/agent').then(({ default: userApi }) => {
userApi.deleteAgent(agentId, (res) => {
if (res.data.code === 0) {
this.$message.success({
message: '删除成功',
showClose: true
});
this.fetchAgentList(); // 刷新列表
} else {
this.$message.error({
message: res.data.msg || '删除失败',
showClose: true
});
}
});
Api.agent.deleteAgent(agentId, (res) => {
if (res.data.code === 0) {
this.$message.success({
message: '删除成功',
showClose: true
});
this.fetchAgentList(); // 刷新列表
} else {
this.$message.error({
message: res.data.msg || '删除失败',
showClose: true
});
}
});
}).catch(() => { });
}
-1
View File
@@ -84,7 +84,6 @@ export default {
},
methods: {
fetchCaptcha() {
console.log(this.$store.getters.getToken)
if (this.$store.getters.getToken) {
if (this.$route.path !== '/home') {
this.$router.push('/home')
-1
View File
@@ -143,7 +143,6 @@ export default {
}
Api.user.register(this.form, ({ data }) => {
console.log(data)
if (data.code === 0) {
showSuccess('注册成功!')
goToPage('/login')
+39 -44
View File
@@ -96,8 +96,10 @@
</template>
<script>
import Api from '@/apis/api';
import HeaderBar from "@/components/HeaderBar.vue";
export default {
name: 'RoleConfigPage',
components: { HeaderBar },
@@ -153,14 +155,12 @@ export default {
language: this.form.language,
sort: this.form.sort
};
import('@/apis/module/agent').then(({ default: agentApi }) => {
agentApi.updateAgentConfig(this.$route.query.agentId, configData, ({ data }) => {
if (data.code === 0) {
this.$message.success('配置保存成功');
} else {
this.$message.error(data.msg || '配置保存失败');
}
});
Api.agent.updateAgentConfig(this.$route.query.agentId, configData, ({ data }) => {
if (data.code === 0) {
this.$message.success('配置保存成功');
} else {
this.$message.error(data.msg || '配置保存失败');
}
});
},
resetConfig() {
@@ -194,24 +194,22 @@ export default {
selectTemplate(templateName) {
if (this.loadingTemplate) return;
this.loadingTemplate = true;
import('@/apis/module/agent').then(({ default: agentApi }) => {
agentApi.getAgentTemplate((response) => { // 移除参数传递
this.loadingTemplate = false;
if (response.data.code === 0) {
// 在客户端过滤匹配的模板
const matchedTemplate = response.data.data.find(
t => t.agentName === templateName
);
if (matchedTemplate) {
this.applyTemplateData(matchedTemplate);
this.$message.success(`${templateName}」模板已应用`);
} else {
this.$message.warning(`未找到「${templateName}」模板`);
}
Api.agent.getAgentTemplate((response) => { // 移除参数传递
this.loadingTemplate = false;
if (response.data.code === 0) {
// 在客户端过滤匹配的模板
const matchedTemplate = response.data.data.find(
t => t.agentName === templateName
);
if (matchedTemplate) {
this.applyTemplateData(matchedTemplate);
this.$message.success(`${templateName}」模板已应用`);
} else {
this.$message.error(response.data.msg || '获取模板失败');
this.$message.warning(`未找到「${templateName}」模板`);
}
});
} else {
this.$message.error(response.data.msg || '获取模板失败');
}
}).catch((error) => {
this.loadingTemplate = false;
this.$message.error('模板加载失败');
@@ -236,25 +234,23 @@ export default {
};
},
fetchAgentConfig(agentId) {
import('@/apis/module/agent').then(({ default: agentApi }) => {
agentApi.getDeviceConfig(agentId, ({ data }) => {
if (data.code === 0) {
this.form = {
...this.form,
...data.data,
model: {
ttsModelId: data.data.ttsModelId,
vadModelId: data.data.vadModelId,
asrModelId: data.data.asrModelId,
llmModelId: data.data.llmModelId,
memModelId: data.data.memModelId,
intentModelId: data.data.intentModelId
}
};
} else {
this.$message.error(data.msg || '获取配置失败');
}
});
Api.agent.getDeviceConfig(agentId, ({ data }) => {
if (data.code === 0) {
this.form = {
...this.form,
...data.data,
model: {
ttsModelId: data.data.ttsModelId,
vadModelId: data.data.vadModelId,
asrModelId: data.data.asrModelId,
llmModelId: data.data.llmModelId,
memModelId: data.data.memModelId,
intentModelId: data.data.intentModelId
}
};
} else {
this.$message.error(data.msg || '获取配置失败');
}
});
},
// 清空记忆体内容
@@ -265,7 +261,6 @@ export default {
},
mounted() {
const agentId = this.$route.query.agentId;
console.log('agentId2222', agentId);
if (agentId) {
this.fetchAgentConfig(agentId);
}