cshenfu
2023-06-02 82be1991acab9b8d15c78fb6e2d6e9d9069074fa
add cliend_id
7个文件已修改
451 ■■■■■ 已修改文件
common/config.js 4 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/index/chat.vue 124 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/index/home.vue 1 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/index/index.vue 128 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/index/question.vue 89 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/index/write.vue 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/mine/mine.vue 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/config.js
@@ -3,8 +3,8 @@
  // ws: 'ws://192.168.0.104:7272',  // 本地socket
    // base_url: 'https://newgpt.nauzone.cn',
    // ws: 'wss://newgpt.nauzone.cn/wss',
    base_url: 'http://ai.shsening.com',
    ws: 'ws://ai.shsening.com/wss',
    base_url: 'https://ai.shsening.com',
    ws: 'wss://ai.shsening.com/wss',
    official_accounts_appid: 'wxa447f988edc97797'
}
pages/index/chat.vue
@@ -122,6 +122,7 @@
        mixins: [mixin],
        data() {
            return {
                client_id: "",
                prompt: '',
                arr: [],
                timer: null,
@@ -183,19 +184,58 @@
            });
            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')) {
                    that.typeingId = json.id
                    if (!json.choices[0].delta.finish_reason) {
                        if (json.choices[0].delta.hasOwnProperty('content')) {
                            that.typeingText += json.choices[0].delta.content
                            // 此处自行斟酌是否替换
                            // that.typeingText = that.typeingText.replace(/[cogptn]+/ig, "ChatGLM-6B")
                if (json.hasOwnProperty('type') && json.type == 'content') {
                    that.typeingText = json.content;
                    that.$nextTick(() => {
                        uni.pageScrollTo({
                            scrollTop: 20000,
                            duration: 100
                        });
                    });
                }
                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: that.userInfo.member_id
                                // uid: 3
                            })
                        })
                    }
                    if (json.type == 'content') {
                        that.loading = false;
                        that.typeingText = "";
                        that.typeingId = "";
                        that.arr.push({
                            role: json.content.role,
                            content: json.content.content,
                        });
                        if (!that.chat_id) {
                            that.chat_id = json.content.chat_id
                            that.chatList[0].chat_id = json.content.chat_id
                            that.chatList[0].title = 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) {
@@ -334,14 +374,32 @@
                    this.$failToast("请输入内容");
                    return;
                }
                this.loading = true;
                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.sendout()
                            }, 300)
                        }
                    })
                    return
                }
                this.arr.push({
                    role: 'user',
                    content: this.prompt,
                    message_id: this.arr.length + 1
                });
                let message = this.prompt;
                this.prompt = ""
                this.$nextTick(() => {
                    uni.pageScrollTo({
@@ -354,12 +412,14 @@
                }, 200);
            },
            sub(message) {
                this.goon = false;
                // 条件编译处理,h5端uni.request与socket会互相阻塞
                // #ifndef H5
                this.$request("/api/Message/sendV2", "POST", {
                    message: message,
                    chat_id: this.chat_id,
                    model_id: this.now_model.assistant_id
                    model_id: this.now_model.assistant_id,
                    client_id: this.client_id
                    // member_id: 3 // 调试之用,线上环境为token解码
                }).then((res) => {
                    console.log(res);
@@ -378,6 +438,9 @@
                            this.chatList[0].title = message
                            this.chat_id = res.data.chat_id
                        }
                        if (res.data.finish_reason == 'length') {
                            this.goon = true;
                        }
                        this.$store.commit('useNum', 1);
                        this.$nextTick(() => {
                            uni.pageScrollTo({
@@ -393,6 +456,13 @@
                        uni.showModal({
                            content: res.msg
                        })
                    } else if (res.status == 403) {
                        this.loading = false;
                        this.$failToast(res.msg);
                        this.arr.pop()
                        this.prompt = res.data
                    } else if (res.status == 600) {
                    } else {
                        this.loading = false;
                        this.$failToast(res.msg);
@@ -410,7 +480,8 @@
                    data: {
                        message: message,
                        chat_id: this.chat_id,
                        model_id: this.now_model.assistant_id
                        model_id: this.now_model.assistant_id,
                        client_id: this.client_id
                    },
                    headers: {
                        'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
@@ -419,6 +490,23 @@
                }).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.loading = false;
                        this.typeingText = "";
@@ -431,6 +519,9 @@
                            this.chatList[0].chat_id = res.data.chat_id
                            this.chatList[0].title = message
                            this.chat_id = res.data.chat_id
                        }
                        if (res.data.finish_reason == 'length') {
                            this.goon = true;
                        }
                        this.$store.commit('useNum', 1);
                        this.$nextTick(() => {
@@ -447,6 +538,13 @@
                        uni.showModal({
                            content: res.msg
                        })
                    } else if (res.status == 403) {
                        this.loading = false;
                        this.$failToast(res.msg);
                        this.arr.pop()
                        this.prompt = res.data
                    } else if (res.status == 600) {
                    } else {
                        this.loading = false;
                        this.$failToast(res.msg);
@@ -455,7 +553,7 @@
                    // reject(error);
                });
                // #endif
            },
            copy(item) {
                uni.setClipboardData({
pages/index/home.vue
@@ -96,6 +96,7 @@
        mixins: [mixin],
        data() {
            return {
                client_id: "",
                showTab: false,
                tabIndex: 0,
                setting_data:'null',
pages/index/index.vue
@@ -78,6 +78,7 @@
    export default {
        data() {
            return {
                client_id: "",
                prompt: '',
                arr: [],
                timer: null,
@@ -138,19 +139,56 @@
            });
            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')) {
                    that.typeingId = json.id
                    if (!json.choices[0].delta.finish_reason) {
                        if (json.choices[0].delta.hasOwnProperty('content')) {
                            that.typeingText += json.choices[0].delta.content
                            // 此处自行斟酌是否替换
                            // that.typeingText = that.typeingText.replace(/[cogptn]+/ig, "ChatGLM-6B")
                if (json.hasOwnProperty('type') && json.type == 'content') {
                    that.typeingText = json.content;
                    that.$nextTick(() => {
                        uni.pageScrollTo({
                            scrollTop: 20000,
                            duration: 100
                        });
                    });
                }
                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: that.userInfo.member_id
                                // uid: 3
                            })
                        })
                    }
                    if (json.type == 'content') {
                        that.loading = false;
                        that.typeingText = "";
                        that.typeingId = "";
                        that.arr.push({
                            role: json.content.role,
                            content: json.content.content,
                        });
                        if (!that.chat_id) {
                            that.chat_id = json.content.chat_id
                        }
                        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) {
@@ -219,8 +257,24 @@
                    this.$failToast("请输入内容");
                    return;
                }
                this.loading = true;
                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.sendout()
                            }, 300)
                        }
                    })
                    return
                }
                this.arr.push({
                    role: 'user',
                    content: this.prompt,
@@ -239,12 +293,14 @@
                }, 200);
            },
            sub(message) {
                this.goon = false;
                // 条件编译处理,h5端uni.request与socket会互相阻塞
                // #ifndef H5
                this.$request("/api/Message/sendV2", "POST", {
                    message: message,
                    chat_id: this.chat_id,
                    model_id: this.now_model.assistant_id
                    model_id: this.now_model.assistant_id,
                    client_id: this.client_id
                    // member_id: 3 // 调试之用,线上环境为token解码
                }).then((res) => {
                    console.log(res);
@@ -254,12 +310,15 @@
                        this.typeingId = "";
                        this.arr.push({
                            role: res.data.role,
                            // 此处自行斟酌是否替换
                            content: res.data.content,
                            // content: res.data.content.replace(/[cogptn]+/ig, "ChatGLM-6B")
                        });
                        if (!this.chat_id) {
                            this.chatList[0].chat_id = res.data.chat_id
                            this.chatList[0].title = message
                            this.chat_id = res.data.chat_id
                        }
                        if (res.data.finish_reason == 'length') {
                            this.goon = true;
                        }
                        this.$store.commit('useNum', 1);
                        this.$nextTick(() => {
@@ -276,6 +335,13 @@
                        uni.showModal({
                            content: res.msg
                        })
                    } else if (res.status == 403) {
                        this.loading = false;
                        this.$failToast(res.msg);
                        this.arr.pop()
                        this.prompt = res.data
                    } else if (res.status == 600) {
                    } else {
                        this.loading = false;
                        this.$failToast(res.msg);
@@ -293,15 +359,35 @@
                    data: {
                        message: message,
                        chat_id: this.chat_id,
                        model_id: this.now_model.assistant_id
                        model_id: this.now_model.assistant_id,
                        client_id: this.client_id
                    },
                    headers: {
                        'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
                        'Authorization': this.$store.state.token
                    }
                }).then(response => {
                    console.log(response)
                    let res = response.data
                    console.log(res)
                    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.loading = false;
                        this.typeingText = "";
@@ -311,7 +397,12 @@
                            content: res.data.content
                        });
                        if (!this.chat_id) {
                            this.chatList[0].chat_id = res.data.chat_id
                            this.chatList[0].title = message
                            this.chat_id = res.data.chat_id
                        }
                        if (res.data.finish_reason == 'length') {
                            this.goon = true;
                        }
                        this.$store.commit('useNum', 1);
                        this.$nextTick(() => {
@@ -328,6 +419,13 @@
                        uni.showModal({
                            content: res.msg
                        })
                    } else if (res.status == 403) {
                        this.loading = false;
                        this.$failToast(res.msg);
                        this.arr.pop()
                        this.prompt = res.data
                    } else if (res.status == 600) {
                    } else {
                        this.loading = false;
                        this.$failToast(res.msg);
@@ -336,7 +434,7 @@
                    // reject(error);
                });
                // #endif
            },
            copy(item) {
                uni.setClipboardData({
pages/index/question.vue
@@ -49,6 +49,7 @@
        mixins: [mixin],
        data() {
            return {
                client_id: "",
                hot_question: [],
                answer: defaultAnswer,
                answerStatus: 0, // 0 是默认状态,1是生成中,2是已生成
@@ -94,20 +95,39 @@
            });
            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
                            });
                        });
                    }
                }
            
@@ -153,6 +173,22 @@
                    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()
@@ -160,8 +196,10 @@
            sub(message) {
                // 条件编译处理,h5端uni.request与socket会互相阻塞
                // #ifndef H5
                this.$request("/api/Message/completions", "POST", {
                this.$request("/api/Message/sendV2", "POST", {
                    message: this.prompt,
                    client_id: this.client_id,
                    type: 'question'
                }).then((res) => {
                    console.log(res);
                    if (res.status == 200) {
@@ -184,6 +222,8 @@
                        uni.showModal({
                            content: res.msg
                        })
                    } else if(res.status == 600) {
                    } else {
                        this.loading = false;
                        this.$failToast(res.msg);
@@ -197,9 +237,11 @@
                // #ifdef H5
                axios({
                    method: 'post',
                    url: setting.base_url + "/api/Message/completions",
                    url: setting.base_url + "/api/Message/sendV2",
                    data: {
                        message: this.prompt,
                        client_id: this.client_id,
                        type: 'question'
                    },
                    headers: {
                        'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
@@ -208,10 +250,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);
                        this.$nextTick(() => {
@@ -228,6 +287,8 @@
                        uni.showModal({
                            content: res.msg
                        })
                    } else if(res.status == 600) {
                    } else {
                        this.loading = false;
                        this.$failToast(res.msg);
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) {
                // 条件编译处理,h5端uni.request与socket会互相阻塞
                // #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 => {
pages/mine/mine.vue
@@ -75,8 +75,8 @@
                </view>
            </view>
            
            <!-- #ifndef MP-WEIXIN -->
            <view v-show="isPC" @click="logout" class="flex item align-center">
            <view @click="logout" class="flex item align-center">
                <u-icon name="/static/icon/quit.png" size="18"></u-icon>
                <view class="flex align-center justify-between solid-bottom margin-left-sm">
                    <view class="title">退出登录</view>
@@ -85,7 +85,6 @@
                    </view>
                </view>
            </view>
            <!-- #endif -->
            <!-- #ifdef MP-WEIXIN -->
            <button open-type="share" class="flex item align-center">
                <u-icon name="/static/icon/mine-share.png" size="18"></u-icon>