diff --git a/miniprogram/app.js b/miniprogram/app.js index 5ee20e3f259b1a58b394413910f2cbae4af723b3..a1ac2115e3cd472fc5582b08691b19050b9bd752 100644 --- a/miniprogram/app.js +++ b/miniprogram/app.js @@ -1,11 +1,14 @@ // app.js App({ + basePage:'pages/aiBot/aiBot', homePageArticleId: 32, lifePageArricleId: 35, wxProgramConfig: { authorPageConfig: { + cloudEmail: "1575057249@qq.com", + cloudPwd: "U2FsdGVkX1+jfEkF2OXTQ5iIG4mrYc5/TLOiIntyENU=", title: "记忆碎片", - userImageUrl: 'https://yongma16.xyz/staticFile/common/img/logo.png', + userImageUrl: 'https://yongma16.xyz/staticFile/common/img/aiTop.jpg', loginTitle: '点击授权', detailInfo: '关于:code笔记', nextPage: "/pages/home/home", @@ -13,6 +16,7 @@ App({ userName: '月牙天冲', designPlaceholder: '自定义名称', joinTitle: '微信登录', + shopBtnTitle: '虚拟资产', isOldVersion: false }, homePageConfig: { @@ -61,7 +65,8 @@ App({ } }, aboutPageConfig: { - articleId: 35 + articleId: 35, + title:'个人信息' } }, loginStatus: '', @@ -77,7 +82,8 @@ App({ targetItem: {}, }, remoteConfig: { - baseUrl: 'https://yongma16.xyz' + baseUrl: 'https://yongma16.xyz', + baseCloudUrl:'https://yongma16.xyz/cloudApi/api/', }, // 引入`towxml3.0`解析方法 towxml: require('/towxml/index'), @@ -166,7 +172,7 @@ App({ if (res.data.data && res.data.data[0].option) { that.wxProgramConfig = JSON.parse(res.data.data[0].option) wx.navigateTo({ - url: 'pages/index/index', + url: that.basePage, success: function (res) { // 通过 eventChannel 向被打开页面传送数据 console.log('res', res) @@ -175,7 +181,7 @@ App({ } else { wx.navigateTo({ - url: 'pages/index/index', + url: that.basePage, success: function (res) { // 通过 eventChannel 向被打开页面传送数据 console.log('res', res) @@ -189,7 +195,7 @@ App({ success: (loadRes) => { console.log(loadRes) }, }) wx.navigateTo({ - url: 'pages/index/index', + url: that.basePage, success: function (res) { // 通过 eventChannel 向被打开页面传送数据 console.log('res', res) @@ -215,7 +221,7 @@ App({ console.log('success') } else { wx.navigateTo({ - url: 'pages/index/index', + url: this.basePage, success: function (res) { // 通过 eventChannel 向被打开页面传送数据 console.log('res', res) diff --git a/miniprogram/app.json b/miniprogram/app.json index 74c9741f4ab86de7d546c70aa0f27ed0d1a84f7e..0c898f6dd62de04d17f5f14c18721ada93fb3c63 100644 --- a/miniprogram/app.json +++ b/miniprogram/app.json @@ -1,19 +1,21 @@ { - "pages": [ - "pages/index/index", - "pages/home/home", - "pages/homeContent/homeContent", - "pages/blog/blog", - "pages/life/life", - "pages/future/future" - ], - "window": { - "backgroundColor": "#F6F6F6", - "backgroundTextStyle": "light", - "navigationBarBackgroundColor": "#262626", - "navigationBarTitleText": "yma16博客", - "navigationBarTextStyle": "white" - }, - "sitemapLocation": "sitemap.json", - "style": "v2" + "pages": [ + "pages/index/index", + "pages/home/home", + "pages/homeContent/homeContent", + "pages/blog/blog", + "pages/life/life", + "pages/future/future", + "pages/shop/shop", + "pages/aiBot/aiBot" + ], + "window": { + "backgroundColor": "#F6F6F6", + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#262626", + "navigationBarTitleText": "yma16博客", + "navigationBarTextStyle": "white" + }, + "sitemapLocation": "sitemap.json", + "style": "v2" } \ No newline at end of file diff --git a/miniprogram/pages/aiBot/aiBot.js b/miniprogram/pages/aiBot/aiBot.js new file mode 100644 index 0000000000000000000000000000000000000000..ad596d82996b5e6becefab3f37fb96b34365cbc5 --- /dev/null +++ b/miniprogram/pages/aiBot/aiBot.js @@ -0,0 +1,260 @@ +// pages/aiBot/aiBot.js + +const app = getApp(); +Page({ + + /** + * 页面的初始数据 + */ + data: { + currentUserInfo: { + nickName: '', + avatarUrl: 'https://profile-avatar.csdnimg.cn/8bea3d4b0c56486691de8f54fb649fa4_qq_38870145.jpg!1', + }, + saveKey: 'aiBot', + baseCloudUrl: app.remoteConfig.baseCloudUrl, + password: app.remoteConfig.cloudPwd || "U2FsdGVkX1+jfEkF2OXTQ5iIG4mrYc5/TLOiIntyENU=", + username: app.remoteConfig.cloudEmail || "1575057249@qq.com", + token: '', + currenTime: '', + isLoading: false, + searchOpenAiText: '画一只猫', + chatObjConfig: { + option: [ + // { + // question: '', + // answer: '', + // isEdit: true, + // createTime: '' + // } + ], + currentIndex: 0, + errorMsg: 'openai的服务器异常!' + }, + layoutConfig: { + showPasteBtn: false, + showTopBtn: false, + introduceText: 'api介绍', + useText: '使用', + returnText: '返回介绍', + sendText: '发送', + searchText: '请输入关键词进行对话', + reportText: '复制数据', + copyText: '复制', + pasteText: '粘贴', + upText: "↑", + downText: "↓", + errorMsg: 'openai的服务器异常!', + emptyText: '欢迎使用aibot', + storageKey: 'openAiOptionsConfig', + permissionTitle: '很抱歉您没有权限!', + permissionContent: '请联系微信号:cse-yma16\r\n 需要1元开通权限\r\n1元可支持100条消息!', + wxInfoImg: 'https://yongma16.xyz/staticFile/common/img/userInfo.png', + limitMsgCount: 10, + confirmText: '添加微信', + cancelText: '返回' + }, + aiConfig: { + avatarUrl: 'https://yongma16.xyz/staticFile/common/img/aiTop.jpg', + bgUrl: 'https://yongma16.xyz/staticFile/common/img/aiBg.jpg', + nickName: 'openai', + }, + }, + getUserToken() { + const that = this + wx.showLoading({ + title: 'gen token loading', + }); + wx.request({ + url: this.data.baseCloudUrl + 'token/gen', + method: 'POST', + data: { + username: this.data.username, + password: this.data.password + }, + success: (res => { + that.setData({ + token: res.data.token + }) + wx.hideLoading() + }), + fail: r => { + console.log('cloud r', r) + wx.hideLoading() + } + }) + }, + getCurrentTime() { + const now = new Date() + const year = now.getFullYear() + const month = now.getMonth() + const date = now.getDate() + const hour = now.getHours() + const minutes = now.getMinutes() + const second = now.getSeconds() + const formatNum = (n) => { + return n > 9 ? n.toString() : '0' + n + } + return `${year}-${formatNum(month + 1)}-${formatNum(date)} ${formatNum(hour)}:${formatNum(minutes)}:${formatNum(second)}` + }, + bindKeyInput(e) { + console.log('e.detail.value', e.detail.value) + this.setData({ + searchOpenAiText: e.detail.value + }) + }, + scrollToBottom() { + const index = this.data.chatObjConfig.option.length - 1 + this.setData({ + toView: `chat-mode${index}` + }) + }, + + search(e) { + this.scrollToBottom() + if (!this.data.searchOpenAiText) { + wx.showModal({ + cancelColor: 'cancelColor', + title: '请输入!' + }) + return + } + wx.showLoading({ + title: '加载中', + }) + this.setData({ + isLoading: true + }) + const that = this + + return new Promise((resolve, reject) => { + wx.request({ + url: that.data.baseCloudUrl + '/chat/bot', + method: 'POST', + header: { + Authorization: `bearer ${that.data.token}` + }, + data: { + user: 'qwerqwre', + query: that.data.searchOpenAiText + }, + success: (res) => { + console.log(res, 'res') + const data = res.data.data + const option = that.data.chatObjConfig.option + console.log('data', data) + const choices = data.messages[2] + const answer = choices?.content + option.push({ + question: that.data.searchOpenAiText, + answer: answer, + answerMarkdown: app.changeMrkdownText(answer), + createTime: that.getCurrentTime(), + isEdit: false, + }) + const chatObjConfig = { + option: option + } + + that.setData({ + isLoading: false, + searchOpenAiText: '', + chatObjConfig: chatObjConfig + }) + wx.hideLoading() + that.scrollToBottom() + resolve(res) + console.log('that.data.chatObjConfig.option', that.data.chatObjConfig.option) + + }, + fail: error => { + that.setData({ + isLoading: false + }) + wx.hideLoading() + } + }); + }) + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad(options) { + this.getUserToken() + this.setData({ + currenTime: this.getCurrentTime() + }) + + const currentUserInfo = wx.getStorageSync('currentUserInfo') + if (currentUserInfo && currentUserInfo.nickName) { + console.log('currentUserInfo', currentUserInfo) + this.setData({ + currentUserInfo: currentUserInfo + }) + } + + // 缓存 + const openAiOptionsConfig = wx.getStorageSync(this.data.saveKey) + + if (openAiOptionsConfig) { + this.setData({ + chatObjConfig: openAiOptionsConfig, + }) + } + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady() { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow() { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide() { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload() { + // 缓存 + + if (this.data.openAiOptionsConfig) { + wx.setStorageSync(this.data.saveKey, this.data.openAiOptionsConfig) + } + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh() { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom() { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage() { + + } +}) \ No newline at end of file diff --git a/miniprogram/pages/aiBot/aiBot.json b/miniprogram/pages/aiBot/aiBot.json new file mode 100644 index 0000000000000000000000000000000000000000..caf09fa9057d192f4debf1b1ef367093ba2feb0f --- /dev/null +++ b/miniprogram/pages/aiBot/aiBot.json @@ -0,0 +1,5 @@ +{ + "usingComponents": { + "towxml":"/towxml/towxml" + } +} \ No newline at end of file diff --git a/miniprogram/pages/aiBot/aiBot.wxml b/miniprogram/pages/aiBot/aiBot.wxml new file mode 100644 index 0000000000000000000000000000000000000000..73410659d8d529eb701d845f66c1d8cd262b1dae --- /dev/null +++ b/miniprogram/pages/aiBot/aiBot.wxml @@ -0,0 +1,86 @@ + + + + + + + {{item.createTime}} + + + + + + + {{item.question}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{currenTime}} + + + + + + + + + + + + {{layoutConfig.emptyText}} + + + + + + +