From d87bfb13f21fbb162fe2598c3b7f70ed3b33e603 Mon Sep 17 00:00:00 2001 From: yma16 <17685043634@163.com> Date: Sun, 19 Feb 2023 00:16:39 +0800 Subject: [PATCH] =?UTF-8?q?perf:=E5=8A=A8=E6=80=81=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=96=87=E5=AD=97=E5=92=8C=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- miniprogram/app.js | 164 +++++++---- miniprogram/app.json | 2 +- miniprogram/pages/future/future.js | 295 +++++++++++-------- miniprogram/pages/future/future.json | 3 - miniprogram/pages/future/future.wxml | 80 ++--- miniprogram/pages/future/future.wxss | 32 +- miniprogram/pages/home/home.js | 89 ++++-- miniprogram/pages/home/home.wxml | 14 +- miniprogram/pages/homeContent/homeContent.js | 8 +- miniprogram/pages/index/index.js | 107 +++++-- miniprogram/pages/index/index.wxml | 37 ++- miniprogram/pages/index/index.wxss | 6 +- miniprogram/pages/life/life.js | 2 +- project.config.json | 34 ++- project.private.config.json | 41 --- 16 files changed, 549 insertions(+), 367 deletions(-) diff --git a/README.md b/README.md index 674dab1..acfae4c 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ ### 云开发小程序 -# 接入markdown \ No newline at end of file +# 接入markdown博客 \ No newline at end of file diff --git a/miniprogram/app.js b/miniprogram/app.js index 44d34f9..cba9abe 100644 --- a/miniprogram/app.js +++ b/miniprogram/app.js @@ -1,23 +1,71 @@ // app.js App({ - homePageArticleId:32, - lifePageArricleId:35, + homePageArticleId: 32, + lifePageArricleId: 35, + wxProgramConfig: { + authorPageConfig: { + title: "记忆碎片", + userImageUrl: 'https://yongma16.xyz/staticFile/common/img/logo.png', + loginTitle: '点击授权', + detailInfo: '关于:code笔记', + nextPage: "/pages/home/home", + userPrefix: '昵称:', + userName: '月牙天冲', + designPlaceholder: '自定义名称', + joinTitle: '进入', + isOldVersion: false + }, + homePageConfig: { + headBackground: [ + { class: 'header-swiper-one', content: '数据分析', articleId: 32, img: 'https://yongma16.xyz/staticFile/common/img/data.png' }, + { class: 'header-swiper-two', content: '前端开发', articleId: 33, img: 'https://yongma16.xyz/staticFile/common/img/front.png' }, + { class: 'header-swiper-three', content: '全栈开发', articleId: 34, img: 'https://yongma16.xyz/staticFile/common/img/back.png' }], + bottomStyleConfig: { + tabMenuText: '记忆碎片', + homePageText: '主页', + blogText: '博客', + apiText: 'openai', + aboutText: '关于' + }, + bottomBtn: 'target', + }, + apiPageConfig: { + articleId: 44, + aiConfig: { + avatarUrl: 'https://yongma16.xyz/staticFile/common/img/aiTop.jpg', + bgUrl: 'https://yongma16.xyz/staticFile/common/img/aiBg.jpg' + }, + mode: 'openAiUse', + option: 'introduce,openAiUse', + layoutConfig: { + introduceText: 'api介绍', + useText: '使用', + returnText: '返回介绍', + sendText: '发送', + searchText: '关键词查询' + } + }, + aboutPageConfig: { + articleId: 35 + } + }, + loginStatus: '', globalData: { userInfo: '', - hasUserInfo:false, - geoJson:{}, - hotData:[], + hasUserInfo: false, + geoJson: {}, + hotData: [], /** * @type object[{name:'',adcode:''}] */ - geoAdcodeMap:[], - targetItem:{}, + geoAdcodeMap: [], + targetItem: {}, }, - remoteConfig:{ - baseUrl:'https://yongma16.xyz' + remoteConfig: { + baseUrl: 'https://yongma16.xyz' }, - // 引入`towxml3.0`解析方法 - towxml:require('/towxml/index'), + // 引入`towxml3.0`解析方法 + towxml: require('/towxml/index'), getUserProfile: function (e) { // 推荐使用 wx.getUserProfile 获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认 // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 @@ -32,7 +80,25 @@ App({ }) }, onLaunch: function (options) { - console.log('start') + console.log('onLaunch', options) + // 获取配置项目 + const that = this + wx.request({ + url: 'https://yongma16.xyz/api/dictModel/index/', + method: 'POST', + data: { + kind: 'wxConfig' + }, success: function (res) { + console.log('res', res) + if (res.data.data) { + console.log('JSON.parse(res.data.data)', JSON.parse(res.data.data[0].option)) + that.wxProgramConfig = JSON.parse(res.data.data[0].option) + } + }, + fail: function (r) { + console.log('r', r) + } + }) if (!wx.cloud) { console.error('请使用 2.2.3 或以上的基础库以使用云能力'); } else { @@ -44,50 +110,42 @@ App({ // env: 'my-env-id', traceUser: true, }); - } - // 用户授权 - wx.getUserProfile({ - desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 - success: (res) => { - console.info('用户授权', res) - this.setData({ - globalData:{userInfo: res.userInfo,hasUserInfo: true}, + wx.removeStorageSync('currentUserInfo'); + wx.navigateTo({ + url: 'pages/index/index', + success: function (res) { + // 通过 eventChannel 向被打开页面传送数据 + console.log('res', res) + } + }); + const currentUserInfo = wx.getStorageSync('currentUserInfo') + if (currentUserInfo && currentUserInfo.nickName) { + console.log('success') + } else { + wx.navigateTo({ + url: 'pages/index/index', + success: function (res) { + // 通过 eventChannel 向被打开页面传送数据 + console.log('res', res) + } }) - wx.setStorageSync('currentUserInfo', res.userInfo) - } - }) - - // 用户登录 - let host = "https://example.com/onLogin" - wx.login({ - success(res) { - console.log('res login', res) - console.log('res code', res.code) - // if (res.code) { - // //发起网络请求 - // wx.request({ - // url: host, - // data: { - // code: res.code - // } - // }) - // } else { - // console.log('登录失败!' + res.errMsg) - // } - } - }) - - - let setting = null; - wx.getSetting({ - success(res) { - setting = res - console.log('res', res) } - }) - this.globalData = { setting: setting }; - console.log('onLaunch', options) + // 用户登录 + const that = this + wx.login({ + success(res) { + console.log('res login', res) + that.globalData.loginStatus = res + } + }) + wx.getSetting({ + success(res) { + console.log('res set', res) + that.globalData.setting = res + } + }) + } }, onShow(options) { diff --git a/miniprogram/app.json b/miniprogram/app.json index bf72be5..74c9741 100644 --- a/miniprogram/app.json +++ b/miniprogram/app.json @@ -11,7 +11,7 @@ "backgroundColor": "#F6F6F6", "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#262626", - "navigationBarTitleText": "阳光罐里的日记", + "navigationBarTitleText": "yma16博客", "navigationBarTextStyle": "white" }, "sitemapLocation": "sitemap.json", diff --git a/miniprogram/pages/future/future.js b/miniprogram/pages/future/future.js index 052d438..f6f0119 100644 --- a/miniprogram/pages/future/future.js +++ b/miniprogram/pages/future/future.js @@ -1,8 +1,9 @@ // pages/future/future.js const app = getApp(); const baseUrl = app.remoteConfig.baseUrl; +const baseArticleId = app.wxProgramConfig.apiPageConfig.articleId; +const baseMode = app.wxProgramConfig.apiPageConfig.mode; Component({ - /** * 继承父级样式 */ @@ -10,80 +11,104 @@ Component({ addGlobalClass: true, }, - // 属性定义 - properties: { - // 用户信息 - userInfo: { - type: Object, - value: ()=>{ - return { + // 属性定义 + properties: { + // 用户信息 + userInfo: { + type: Object, + value: () => { + return { - } - }, - observer: function(newVal, oldVal) { - // 属性值变化时执行 - console.log(newVal,oldVal,'change') } - } - }, + }, + } + }, /** *组件的初始数据 */ data: { - mode:'introduce', - article:{}, - articleId:44, - isShowOenAi:false, - baseUrl:'https://yongma16.xyz/api/', - baseCloudUrl:'https://yongma16.xyz/cloudApi/', - baseCloudPath:'openAiRecord/add', - path:'article/blog/', - currentUserInfo:{ - nickName:'', - avatarUrl:'' + scrollTop: 0, + mode: baseMode, + article: {}, + articleId: baseArticleId, + isShowOenAi: false, + baseUrl: 'https://yongma16.xyz/api/', + baseCloudUrl: 'https://yongma16.xyz/cloudApi/', + baseCloudPath: 'openAiRecord/add', + path: 'article/blog/', + currentUserInfo: { + nickName: '', + avatarUrl: '' }, - aiConfig:{ - avatarUrl:'https://yongma16.xyz/staticFile/common/img/aiTop.jpg', - bgUrl:'https://yongma16.xyz/staticFile/common/img/aiBg.jpg' + aiConfig: { + avatarUrl: 'https://yongma16.xyz/staticFile/common/img/aiTop.jpg', + bgUrl: 'https://yongma16.xyz/staticFile/common/img/aiBg.jpg' }, - searchOpenAiText:'', - responseText:'', + searchOpenAiText: '', + responseText: '', // questions,answer,index - chatObjConfig:{ - option:[{ - question:'', - answer:'', - isEdit:true + chatObjConfig: { + option: [{ + question: '', + answer: '', + isEdit: true }], - currentIndex:0 + currentIndex: 0 + }, + layoutConfig:{ + introduceText:'api介绍', + useText:'使用', + returnText:'返回介绍', + sendText:'发送', + searchText:'关键词查询' + } + }, + observers: { + mode: function (newVal, oldVal) { + // 属性值变化时执行 + console.log(newVal, oldVal, 'change') + wx.showLoading({ + title: '加载中', + }) + // 在当前同步流程结束后,下一个时间片执行 + wx.nextTick(() => { + wx.hideLoading({ + success: (res) => {}, + }) + // 触发父组件事件 + this.triggerEvent('updateBottomNavigation', newVal === 'introduce') + }) + } }, lifetimes: { // 生命周期函数,可以为函数,或一个在 methods 段中定义的方法名 attached: function () { this.getRemoteArticle(this.data.articleId) - const openAiOptions=wx.getStorageSync('openAiOptions') - if(openAiOptions){ + const openAiOptions = wx.getStorageSync('openAiOptions') + if (openAiOptions) { this.setData( { - chatObjConfig:openAiOptions + chatObjConfig: openAiOptions, + mode: app.wxProgramConfig.apiPageConfig.mode, + layoutConfig:app.wxProgramConfig.apiPageConfig.layoutConfig, } ) } - const currentUserInfo=wx.getStorageSync('currentUserInfo') - if(currentUserInfo&¤tUserInfo.nickName){ - console.log('currentUserInfo',currentUserInfo) + const currentUserInfo = wx.getStorageSync('currentUserInfo') + if (currentUserInfo && currentUserInfo.nickName) { + console.log('currentUserInfo', currentUserInfo) this.setData( { - currentUserInfo:currentUserInfo + currentUserInfo: currentUserInfo } ) this.setData({ - isShowOenAi:true + isShowOenAi: true }) } - + }, moved: function () { }, detached: function () { @@ -92,96 +117,108 @@ Component({ }, methods: { - createOpenRecord(params){ - const headers = {'Content-Type':'application/json;charset=UTF-8'} + upper(e) { + console.log('upper e', e) + }, + lower(e) { + console.log('lower e', e) + }, + scroll(e) { + console.log('scroll e', e) + }, + createOpenRecord(params) { + const headers = { 'Content-Type': 'application/json;charset=UTF-8' } wx.request({ url: this.data.baseCloudUrl + this.data.baseCloudPath, headers: headers, - data:params, + data: params, method: 'POST', - success:(res=>{ - console.log('cloud res',res) + success: (res => { + console.log('cloud res', res) }), - fail:r=>{ - console.log('cloud r',r) + fail: r => { + console.log('cloud r', r) } }) }, - scrollToBottom(){ - const viewComponent = this.getEle('#chat-container-id') - console.log('viewComponent',viewComponent) + scrollToBottom() { + const index=this.data.chatObjConfig.option.length-1 + this.setData({ + toView:`chat-mode${index}` + }) }, - getRemoteArticle:function(id){ + getRemoteArticle: function (id) { this.setData({ - isLoading:true + isLoading: true }) - const baseUrl=this.data.baseUrl - const path=this.data.path - const headers = {'Content-Type':'application/json;charset=UTF-8'} - const that=this - const params={ - id:id + const baseUrl = this.data.baseUrl + const path = this.data.path + const headers = { 'Content-Type': 'application/json;charset=UTF-8' } + const that = this + const params = { + id: id } wx.request({ - url: baseUrl+path, - headers:headers, - data:params, - method:'POST', + url: baseUrl + path, + headers: headers, + data: params, + method: 'POST', success: (res) => { - const data=res.data - const articleStr=data&&data.article&&data.article - const markdownText = app.towxml(articleStr,'markdown',{ -        theme:'light', //主题 dark 黑色,light白色,不填默认light -        base: baseUrl+path, - events:{ //为元素绑定的事件方法 - tap:e => { - console.log('tap',e); - }, - change:e => { - console.log('todo',e); - } - } - }); + const data = res.data + const articleStr = data && data.article && data.article + const markdownText = app.towxml(articleStr, 'markdown', { + theme: 'light', //主题 dark 黑色,light白色,不填默认light + base: baseUrl + path, + events: { //为元素绑定的事件方法 + tap: e => { + console.log('tap', e); + }, + change: e => { + console.log('todo', e); + } + } + }); that.setData({ - isLoading:false, - article:markdownText + isLoading: false, + article: markdownText }) } }); }, - changeMode(e){ - const {mode}=e.currentTarget.dataset - console.log(mode,'mode') + changeMode(e) { + const { mode } = e.currentTarget.dataset + console.log(mode, 'mode') this.setData({ - mode:mode + mode: mode }) }, bindKeyInput(e) { - const {columnIndex}=e.currentTarget.dataset - console.log('this.data.chatObjConfig',this.data.chatObjConfig) - const option=this.data.chatObjConfig.option - option.some((item,index)=>{ - if(columnIndex===index){ - item.question=e.detail.value - item.isEdit=true + const { columnIndex } = e.currentTarget.dataset + console.log('this.data.chatObjConfig', this.data.chatObjConfig) + const option = this.data.chatObjConfig.option + option.some((item, index) => { + if (columnIndex === index) { + item.question = e.detail.value + item.isEdit = true return true } return false }) this.setData({ - searchOpenAiText:e.detail.value, - chatObjConfig:{ - option:option, - currentIndex:columnIndex + searchOpenAiText: e.detail.value, + chatObjConfig: { + option: option, + currentIndex: columnIndex } }) }, - search(e){ + search(e) { console.log(this.data.searchOpenAiText) - if(!this.data.searchOpenAiText){ + this.scrollToBottom() + if (!this.data.searchOpenAiText) { wx.showModal({ cancelColor: 'cancelColor', - title:'请输入!' + title: '请输入!' }) return } @@ -194,52 +231,52 @@ Component({ console.log(e) const path = '/common-api/searchOpenAiText/' const headers = { 'Content-Type': 'application/json;charset=UTF-8' } - const params={ - "text":this.data.searchOpenAiText + const params = { + "text": this.data.searchOpenAiText } - const thisBack=this + const thisBack = this return new Promise((resolve, reject) => { wx.request({ url: baseUrl + path, headers: headers, - data:params, + data: params, method: 'GET', success: (res) => { - console.log(res,'res') - const data=res.data.data - const option=thisBack.data.chatObjConfig.option - const currentIndex=thisBack.data.chatObjConfig.currentIndex - const choices=data.choices - console.log('choices',choices) - const answer=choices?choices.map(choicesItem=>{return choicesItem.text}).join('\n'):'。。。未知' - option.some((item,index)=>{ - if(currentIndex===index){ - item.answer=answer - item.isEdit=false + console.log(res, 'res') + const data = res.data.data + const option = thisBack.data.chatObjConfig.option + const currentIndex = thisBack.data.chatObjConfig.currentIndex + const choices = data.choices + console.log('choices', choices) + const answer = choices ? choices.map(choicesItem => { return choicesItem.text }).join('\n') : '。。。未知' + option.some((item, index) => { + if (currentIndex === index) { + item.answer = answer + item.isEdit = false return true } return false }) thisBack.createOpenRecord({ - wx_name:thisBack.data.currentUserInfo.nickName, - wx_img:thisBack.data.currentUserInfo.avatarUrl, - search_text:params.text, - search_response:answer + wx_name: thisBack.data.currentUserInfo.nickName, + wx_img: thisBack.data.currentUserInfo.avatarUrl, + search_text: params.text, + search_response: answer }) - const chatObjConfig={ - option:option, - currentIndex:currentIndex+1 + const chatObjConfig = { + option: option, + currentIndex: currentIndex + 1 } option.push({ - question:'', - answer:'', - isEdit:true + question: '', + answer: '', + isEdit: true }) thisBack.setData( { isLoading: false, - searchOpenAiText:'', - chatObjConfig:chatObjConfig + searchOpenAiText: '', + chatObjConfig: chatObjConfig } ) wx.hideLoading() diff --git a/miniprogram/pages/future/future.json b/miniprogram/pages/future/future.json index d7b07c7..bb8bfb3 100644 --- a/miniprogram/pages/future/future.json +++ b/miniprogram/pages/future/future.json @@ -1,8 +1,5 @@ { "usingComponents": { - "geoMap":"/components/visualComponent/geoMap/geoMap", - "lineChart":"/components/visualComponent/lineChart/lineChart", - "blockInfo":"/components/base/blockInfo/blockInfo", "towxml":"/towxml/towxml" } } diff --git a/miniprogram/pages/future/future.wxml b/miniprogram/pages/future/future.wxml index c8d183d..2303cb9 100644 --- a/miniprogram/pages/future/future.wxml +++ b/miniprogram/pages/future/future.wxml @@ -9,58 +9,60 @@ 分类信息 --> - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - + - - - - - - ({{currentUserInfo.nickName}}): - + + + + + + + ({{currentUserInfo.nickName}}):$ + + + + + ({{currentUserInfo.nickName}}):$ {{item.question}} + + - - - ({{currentUserInfo.nickName}}):$ {{item.question}} + + + + (openai):$ {{item.answer}} + + - + - - - (openai):$ {{item.answer}} - - - - - + + + - - - - -