From 82be1991acab9b8d15c78fb6e2d6e9d9069074fa Mon Sep 17 00:00:00 2001
From: cshenfu <men883234@gmail.com>
Date: 星期五, 02 六月 2023 14:09:58 +0800
Subject: [PATCH] add cliend_id
---
pages/index/write.vue | 100 ++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 81 insertions(+), 19 deletions(-)
diff --git a/pages/index/write.vue b/pages/index/write.vue
index 86d5ad0..63486be 100755
--- a/pages/index/write.vue
+++ b/pages/index/write.vue
@@ -87,6 +87,7 @@
answer: defaultAnswer,
answerStatus: 0, // 0 鏄粯璁ょ姸鎬侊紝1鏄敓鎴愪腑锛�2鏄凡鐢熸垚
desc: "",
+ client_id: "",
title: "",
showTab: false,
tabIndex: 0
@@ -129,23 +130,42 @@
});
uni.onSocketMessage(function(res) {
// console.log('鏀跺埌鏈嶅姟鍣ㄥ唴瀹癸細' + res.data);
- let json = JSON.parse(res.data)
+ let json = JSON.parse(res.data);
// console.log(json)
- if (json.hasOwnProperty('id')) {
- if (that.answerStatus != 1) {
- that.answer = ""
- that.answerStatus = 1;
+ if (json.hasOwnProperty('type') && json.type == 'content') {
+ that.answer = json.content;
+ }
+ if (json.hasOwnProperty('client_id') && json.client_id != '') {
+ console.log('鏇存柊id')
+ that.client_id = json.client_id
+ }
+
+ if (json.status == 200) {
+ if (json.msg == '杩炴帴鎴愬姛') {
+ uni.sendSocketMessage({
+ data: JSON.stringify({
+ type: 'login',
+ uid: userInfo.member_id
+ // uid: 3
+ })
+ })
}
- that.typeingId = json.id
- if (!json.choices[0].delta.finish_reason) {
- if (json.choices[0].delta.hasOwnProperty('content')) {
- that.answer += json.choices[0].delta.content
- // 姝ゅ鑷鏂熼厡鏄惁鏇挎崲
- // that.typeingText = that.typeingText.replace(/[cogptn]+/ig, "ChatGLM-6B")
+ if (json.type == 'content') {
+ that.answerStatus = 2;
+ that.answer = json.content.content
+ if (json.content.finish_reason == 'length') {
+ that.goon = true;
}
+ that.$store.commit('useNum', 1);
+ that.$nextTick(() => {
+ uni.pageScrollTo({
+ scrollTop: 20000,
+ duration: 100
+ });
+ });
}
}
-
+
});
// socket鏂紑鏃堕�氱煡鍚庣鏀瑰彉鐧诲綍鐘舵��
uni.onSocketClose(function(res) {
@@ -188,16 +208,35 @@
this.$failToast("璇疯緭鍏ュ唴瀹�");
return;
}
-
+
+ if (!this.client_id) {
+ let userInfo = uni.getStorageSync('userInfo')
+ uni.sendSocketMessage({
+ data: JSON.stringify({
+ type: 'login',
+ uid: userInfo.member_id,
+ // uid: 3
+ }),
+ success: (r) => {
+ setTimeout(() => {
+ this.submit()
+ }, 300)
+ }
+ })
+ return
+ }
+
this.answer = answerIng;
this.sub()
},
sub(message) {
// 鏉′欢缂栬瘧澶勭悊锛宧5绔痷ni.request涓巗ocket浼氫簰鐩搁樆濉�
// #ifndef H5
- this.$request("/api/Message/write", "POST", {
+ this.$request("/api/Message/sendV2", "POST", {
title: this.title,
desc: this.desc,
+ client_id: this.client_id,
+ type: 'write'
}).then((res) => {
console.log(res);
if (res.status == 200) {
@@ -214,23 +253,27 @@
uni.showModal({
content: res.msg
})
+ } else if(res.status == 600) {
+
} else {
- this.loading = false;
+ this.answerStatus = 2;
this.$failToast(res.msg);
}
}).catch(err => {
console.log(err)
- this.loading = false;
+ this.answerStatus = 2;
this.$failToast(err.errMsg);
})
// #endif
// #ifdef H5
axios({
method: 'post',
- url: setting.base_url + "/api/Message/write",
+ url: setting.base_url + "/api/Message/sendV2",
data: {
title: this.title,
desc: this.desc,
+ client_id: this.client_id,
+ type: 'write'
},
headers: {
'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
@@ -239,10 +282,27 @@
}).then(response => {
console.log(response)
let res = response.data
+ if (res.status == 101 || res.status == 102 || (res.status == 411 && res.msg == '璇风櫥褰�')) {
+ console.log(1)
+ this.$store.commit('logout')
+ uni.removeStorageSync('userInfo')
+ uni.removeStorageSync('token')
+ uni.showModal({
+ title: "鎻愮ず",
+ content: res.msg,
+ success() {
+ uni.reLaunch({
+ url: "/pages/login/newlogin"
+ })
+ }
+ })
+ uni.hideLoading()
+ return
+ }
if (res.status == 200) {
this.answerStatus = 2;
setTimeout(() => {
- this.answer = res.data
+ this.answer = res.data.content
}, 500);
this.$store.commit('useNum', 1);
@@ -254,8 +314,10 @@
uni.showModal({
content: res.msg
})
+ } else if(res.status == 600) {
+
} else {
- this.loading = false;
+ this.answerStatus = 2;
this.$failToast(res.msg);
}
}).catch(error => {
--
Gitblit v1.9.1