diff --git a/README.md b/README.md
index 674dab1ab4941419d4000da40076dd9793886e40..acfae4c144f0bc2ad5514d2e27e5918855dd8154 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 44d34f9a496a25dd47523e59bb7dba3e3353ec18..cba9abe523fd03df52812e47ab287e404147ae50 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 bf72be584e49ad62501e48144343d592d5953164..74c9741f4ab86de7d546c70aa0f27ed0d1a84f7e 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 052d438adfe6383e822c88ffce1b1c32f037472a..f6f01193514c397cbf0a9246b17d2969f58bbccc 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 d7b07c726bc6fdec0b10b3e2d24472753b109da5..bb8bfb37b6cf68ce1b9522ab6b3da91b9c31b2dc 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 c8d183dfcf194d097fd00e62a09e829953853047..2303cb9aa7702cce72d05e56e73f0b65815753e9 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}}
-
-
-
-
-
+
+
+
-
-
-
-
-