瀏覽代碼

绑定设备改为扫码后暂存后到添加角色页面再绑定添加角色

htc 1 天之前
父節點
當前提交
76715d658d
共有 5 個文件被更改,包括 76 次插入46 次删除
  1. 14 10
      components/bindDevice/index.vue
  2. 13 10
      pagesMy/device.vue
  3. 5 6
      pagesMy/scanResult.vue
  4. 13 10
      pagesMy/wifiSuccess.vue
  5. 31 10
      pagesRole/addRole.vue

+ 14 - 10
components/bindDevice/index.vue

@@ -36,17 +36,21 @@
 					success: (res) => {
 						let result = JSON.parse(res.result);
 						if(res.errMsg==='scanCode:ok'){
-							that.$api.post('/device/bind',{
-								...result,
-								"type": "",
-								"userId": 0,
-								"agentId": ""
-							}).then(res=>{
-								if(res.data.code!==0) return that.$showToast(res.data.msg)
-								uni.navigateTo({
-									url:'/pagesMy/scanResult?deviceId='+res.data.data
-								})
+							uni.navigateTo({
+								url:'/pagesMy/scanResult?scanParams='+JSON.stringify(result)
 							})
+							
+							// that.$api.post('/device/bind',{
+							// 	...result,
+							// 	"type": "",
+							// 	"userId": 0,
+							// 	"agentId": ""
+							// }).then(res=>{
+							// 	if(res.data.code!==0) return that.$showToast(res.data.msg)
+							// 	uni.navigateTo({
+							// 		url:'/pagesMy/scanResult?deviceId='+res.data.data
+							// 	})
+							// })
 						}
 					}
 				})

+ 13 - 10
pagesMy/device.vue

@@ -69,17 +69,20 @@
 					success: (res) => {
 						let result = JSON.parse(res.result);
 						if(res.errMsg==='scanCode:ok'){
-							that.$api.post('/device/bind',{
-								...result,
-								"type": "",
-								"userId": 0,
-								"agentId": ""
-							}).then(res=>{
-								if(res.data.code!==0) return that.$showToast(res.data.msg)
-								uni.navigateTo({
-									url:'/pagesMy/scanResult?deviceId='+res.data.data
-								})
+							uni.navigateTo({
+								url:'/pagesMy/scanResult?scanParams='+JSON.stringify(result)
 							})
+							// that.$api.post('/device/bind',{
+							// 	...result,
+							// 	"type": "",
+							// 	"userId": 0,
+							// 	"agentId": ""
+							// }).then(res=>{
+							// 	if(res.data.code!==0) return that.$showToast(res.data.msg)
+							// 	uni.navigateTo({
+							// 		url:'/pagesMy/scanResult?deviceId='+res.data.data
+							// 	})
+							// })
 						}
 					}
 				})

+ 5 - 6
pagesMy/scanResult.vue

@@ -2,10 +2,9 @@
 	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
 		<cus-header title='扫码结果'></cus-header>
 		<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/ea285d8f-ad96-447e-8f4a-77d495f2fac6.png"></image>
-		<p>设备绑定成功</p>
-		<p class="tip">您可以创建新角色,或选择已有角色<br>配置到当前设备</p>
+		<p>扫码成功</p>
+		<p class="tip">设备已就绪,需添加角色才能使用<br>快去创建角色吧~</p>
 		<div class="zt_btn" @tap="addRole">为设备添加角色</div>
-		<div class="qx_btn" @tap="goBack">返回首页</div>
 	</view>
 </template>
 
@@ -13,16 +12,16 @@
 	export default {
 		data(){
 			return {
-				deviceId:''
+				scanParams:''
 			}
 		},
 		onLoad(option) {
-			this.deviceId = option.deviceId;
+			if(option.scanParams) this.scanParams = JSON.parse(option.scanParams);
 		},
 		methods:{
 			addRole(){
 				uni.navigateTo({
-					url:'/pagesRole/addRole?type=1&deviceId='+this.deviceId
+					url:'/pagesRole/addRole?type=1&scanParams='+JSON.stringify(this.scanParams)
 				})
 			},
 			goBack(){

+ 13 - 10
pagesMy/wifiSuccess.vue

@@ -23,17 +23,20 @@
 					success: (res) => {
 						let result = JSON.parse(res.result);
 						if(res.errMsg==='scanCode:ok'){
-							that.$api.post('/device/bind',{
-								...result,
-								"type": "",
-								"userId": 0,
-								"agentId": ""
-							}).then(res=>{
-								if(res.data.code!==0) return that.$showToast(res.data.msg)
-								uni.navigateTo({
-									url:'/pagesMy/scanResult?deviceId='+res.data.data
-								})
+							uni.navigateTo({
+								url:'/pagesMy/scanResult?scanParams='+JSON.stringify(result)
 							})
+							// that.$api.post('/device/bind',{
+							// 	...result,
+							// 	"type": "",
+							// 	"userId": 0,
+							// 	"agentId": ""
+							// }).then(res=>{
+							// 	if(res.data.code!==0) return that.$showToast(res.data.msg)
+							// 	uni.navigateTo({
+							// 		url:'/pagesMy/scanResult?deviceId='+res.data.data
+							// 	})
+							// })
 						}
 					}
 				})

+ 31 - 10
pagesRole/addRole.vue

@@ -87,7 +87,8 @@
 					"chatHistoryConf": ""
 				},
 				imageUrl:'',
-				resultUrl:''
+				resultUrl:'',
+				scanParams:''
 			}
 		},
 		onLoad(option) {
@@ -96,12 +97,13 @@
 				if(option.type==1) this.backUrl = '/pages/home'
 				else if(option.type==2) this.backUrl = '/pages/role'
 			}
-			this.deviceId = option.deviceId;
+			// this.deviceId = option.deviceId;
 			if(option.agentId){
 				this.title = '编辑角色';
 				this.agentId = option.agentId;
 				this.getDetail();
 			} 
+			if(option.scanParams) this.scanParams = JSON.parse(option.scanParams)
 			this.getModelVoiceList();
 		},
 		watch:{
@@ -188,7 +190,7 @@
 				if(this.agentDto.voiceText==='请选择音色') return this.$showToast('请选择音色')
 				
 				let dto = JSON.parse(JSON.stringify(this.agentDto));
-				if(this.deviceId) dto.deviceId = this.deviceId;
+				// if(this.deviceId) dto.deviceId = this.deviceId;
 				//默认固定值(暂时)
 				dto.asrModelId = 'ASR_FunASR';
 				dto.vadModelId = 'VAD_SileroVAD';
@@ -201,13 +203,32 @@
 				dto.language = '中文';
 				dto.vllmModelId = 'VLLM_ChatGLMVLLM';
 				dto.avatar = this.resultUrl;
-				this.$api.post(this.agentId?`/agent/update/${this.agentId}`:'/agent',dto).then(res=>{
-					if(res.data.code!==0) return this.$showToast(res.data.msg)
-					this.$showToast(this.agentId?'编辑成功':'创建成功');
-					setTimeout(()=>{
-						uni.reLaunch({ url:this.type==1?'/pages/home':'/pages/role' })
-					},1500)
-				})
+				if(this.scanParams){
+					this.$api.post('/device/bind',{
+						...this.scanParams,
+						"type": "",
+						"userId": 0,
+						"agentId": ""
+					}).then(res=>{
+						if(res.data.code!==0) return this.$showToast(res.data.msg)
+						dto.deviceId = res.data.data;
+						this.$api.post('/agent',dto).then(res2=>{
+							if(res2.data.code!==0) return this.$showToast(res2.data.msg)
+							this.$showToast('设备绑定成功');
+							setTimeout(()=>{
+								uni.reLaunch({ url:'/pages/home' })
+							},1500)
+						})
+					})
+				}else{
+					this.$api.post(this.agentId?`/agent/update/${this.agentId}`:'/agent',dto).then(res=>{
+						if(res.data.code!==0) return this.$showToast(res.data.msg)
+						this.$showToast(this.agentId?'编辑成功':'创建成功');
+						setTimeout(()=>{
+							uni.reLaunch({ url:this.type==1?'/pages/home':'/pages/role' })
+						},1500)
+					})
+				}
 			},
 			getDetail(){
 				this.$api.get(`/agent/${this.agentId}`).then(res=>{