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