diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 7e1fd50931172a3169d7412149819fec93d8ca31..2e884052f835805ef35b93e640f508c13c1e9e8b 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,18 +1,12 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
+
@@ -25,7 +19,7 @@
-
+
@@ -37,6 +31,15 @@
+
+
+
+
+
+
+
+
+
@@ -46,6 +49,7 @@
@@ -61,10 +65,9 @@
-
-
-
-
+
+
+
@@ -72,6 +75,7 @@
+
@@ -95,6 +99,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -106,10 +124,10 @@
-
+
@@ -147,6 +165,7 @@
1665923387310
+
1665930867783
@@ -159,12 +178,12 @@
-
+
-
+
@@ -175,18 +194,28 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
@@ -202,5 +231,12 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/miniprogram/app.js b/miniprogram/app.js
index cba9abe523fd03df52812e47ab287e404147ae50..026c88f6e8744c25478a3af74cae8ff382ff488c 100644
--- a/miniprogram/app.js
+++ b/miniprogram/app.js
@@ -42,7 +42,21 @@ App({
useText: '使用',
returnText: '返回介绍',
sendText: '发送',
- searchText: '关键词查询'
+ searchText: '关键词查询',
+ reportText: '复制数据',
+ copyText: '复制',
+ pasteText: '粘贴',
+ upText: "↑",
+ downText: "↓",
+ errorMsg: 'openai的服务器异常!',
+ emptyText: '欢迎',
+ 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: '返回'
}
},
aboutPageConfig: {
@@ -66,6 +80,31 @@ App({
},
// 引入`towxml3.0`解析方法
towxml: require('/towxml/index'),
+ /**
+ * 转换text
+ * @param {string} text
+ */
+ changeMrkdownText(text) {
+ const markdownText = this.towxml(text, 'markdown', {
+ theme: 'light', //主题 dark 黑色,light白色,不填默认light
+ events:{
+ tap:(e)=>{
+ console.log('e',e)
+ if(e&&e.target&&e.target.dataset.data){
+ const {attrs,tag}=e.target.dataset.data
+ if(tag==='img'){
+ const {src}=attrs
+ wx.previewImage({
+ current: src, // 当前显示图片的http链接
+ urls: [src] // 需要预览的图片http链接列表
+ })
+ }
+ }
+ }
+ }
+ });
+ return markdownText
+ },
getUserProfile: function (e) {
// 推荐使用 wx.getUserProfile 获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
@@ -83,6 +122,9 @@ App({
console.log('onLaunch', options)
// 获取配置项目
const that = this
+ wx.showLoading({
+ title: '加载配置中',
+ })
wx.request({
url: 'https://yongma16.xyz/api/dictModel/index/',
method: 'POST',
@@ -90,13 +132,41 @@ App({
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))
+ wx.hideLoading({
+ success: (loadRes) => { console.log(loadRes) },
+ })
+ if (res.data.data && res.data.data[0].option) {
that.wxProgramConfig = JSON.parse(res.data.data[0].option)
+ wx.navigateTo({
+ url: 'pages/index/index',
+ success: function (res) {
+ // 通过 eventChannel 向被打开页面传送数据
+ console.log('res', res)
+ }
+ });
+ }
+ else {
+ wx.navigateTo({
+ url: 'pages/index/index',
+ success: function (res) {
+ // 通过 eventChannel 向被打开页面传送数据
+ console.log('res', res)
+ }
+ });
}
},
fail: function (r) {
console.log('r', r)
+ wx.hideLoading({
+ success: (loadRes) => { console.log(loadRes) },
+ })
+ wx.navigateTo({
+ url: 'pages/index/index',
+ success: function (res) {
+ // 通过 eventChannel 向被打开页面传送数据
+ console.log('res', res)
+ }
+ });
}
})
if (!wx.cloud) {
@@ -111,13 +181,7 @@ App({
traceUser: 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')
diff --git a/miniprogram/pages/blog/blog.js b/miniprogram/pages/blog/blog.js
index c8fe6caa32657107db5c7486923465eb634905aa..97196bc7fd58a9516044f54b6f4edf1aa3b83fbc 100644
--- a/miniprogram/pages/blog/blog.js
+++ b/miniprogram/pages/blog/blog.js
@@ -72,9 +72,7 @@ Component({
}
})
const articleStr=data&&data.article&&data.article[0]
- const markdownText = app.towxml(articleStr,'markdown',{
- theme:'light', //主题 dark 黑色,light白色,不填默认light
- });
+ const markdownText = app.changeMrkdownText(articleStr)
that.setData({
isLoading:false,
currentTitle:articleTitle&&articleTitle[0].title,
diff --git a/miniprogram/pages/blog/blog.wxss b/miniprogram/pages/blog/blog.wxss
index f32f647c3114ba2f4ef920452a66a793142e8b90..5932516c703ea1e2bae54ef9b5485bb588c469a4 100644
--- a/miniprogram/pages/blog/blog.wxss
+++ b/miniprogram/pages/blog/blog.wxss
@@ -21,12 +21,14 @@
width: 100vw;
height: calc(100vh - 110px);
overflow: auto;
+ user-select: text;
}
.blog-container{
margin-top:100px;
width: 100vw;
height: auto;
margin-bottom:10px;
+ user-select: text;
}
.blog-title{
text-align: center;
@@ -38,4 +40,8 @@
padding: 10px;
width: 100%;
min-height: 20px;
+ box-shadow: 0 2rpx 5rpx 5rpx #c8c3c3;
+}
+.blog-title:active,.blog-title:hover{
+ color:#fff;
}
\ No newline at end of file
diff --git a/miniprogram/pages/future/future.js b/miniprogram/pages/future/future.js
index ba2e12cce061f17ab95eebb85730ba2f4e93f4de..1226955c6596136f3cd21121bbb6159efc6d3cab 100644
--- a/miniprogram/pages/future/future.js
+++ b/miniprogram/pages/future/future.js
@@ -27,14 +27,18 @@ Component({
*组件的初始数据
*/
data: {
+ currenTime: "",
scrollTop: 0,
mode: baseMode,
article: {},
articleId: baseArticleId,
- isShowOenAi: false,
+ isShowOenAi: true,
baseUrl: 'https://yongma16.xyz/api/',
baseCloudUrl: 'https://yongma16.xyz/cloudApi/',
- baseCloudPath: 'openAiRecord/add',
+ baseCloudAddRecordPath: 'openAiRecord/add',
+ baseCloudUpdateUserPath: 'userModel/update',
+ baseCloudgetUserPath: 'userModel/info',
+ baseCloudGetRecordCountPath: 'openAiRecord/count',
path: 'article/blog/',
currentUserInfo: {
nickName: '',
@@ -50,13 +54,16 @@ Component({
reportText: '',
// questions,answer,index
chatObjConfig: {
- option: [{
- question: '',
- answer: '',
- isEdit: true,
- createTime: ''
- }],
- currentIndex: 0
+ option: [
+ // {
+ // question: '',
+ // answer: '',
+ // isEdit: true,
+ // createTime: ''
+ // }
+ ],
+ currentIndex: 0,
+ errorMsg: 'openai的服务器异常!'
},
layoutConfig: {
introduceText: 'api介绍',
@@ -65,8 +72,23 @@ Component({
sendText: '发送',
searchText: '关键词查询',
reportText: '复制数据',
- copyText: '复制'
- }
+ copyText: '复制',
+ pasteText: '粘贴',
+ upText: "↑",
+ downText: "↓",
+ errorMsg: 'openai的服务器异常!',
+ emptyText: '欢迎',
+ 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:'返回'
+ },
+ msgCount: 0,
+ isVip: false,
+ modalVisible: false
},
observers: {
mode: function (newVal, oldVal) {
@@ -89,18 +111,34 @@ Component({
lifetimes: {
// 生命周期函数,可以为函数,或一个在 methods 段中定义的方法名
attached: function () {
+
+ this.getUserInfo()
this.getRemoteArticle(this.data.articleId)
- const openAiOptions = wx.getStorageSync('openAiOptions')
- if (openAiOptions) {
+ this.setData({
+ currenTime: this.getCurrentTime()
+ })
+ const key = app.wxProgramConfig.apiPageConfig.layoutConfig.storageKey
+ const openAiOptionsConfig = wx.getStorageSync(key)
+
+ if (openAiOptionsConfig) {
+ // if (openAiOptionsConfig.option) {
+ // openAiOptionsConfig.option.forEach(item => {
+ // item.answerMarkdown = app.changeMrkdownText(item.answer)
+ // })
+ // }
+ const lauoutConfig=app.wxProgramConfig.apiPageConfig.layoutConfig
this.setData(
{
- chatObjConfig: openAiOptions,
+ chatObjConfig: openAiOptionsConfig,
mode: app.wxProgramConfig.apiPageConfig.mode,
- layoutConfig: app.wxProgramConfig.apiPageConfig.layoutConfig,
+ layoutConfig:lauoutConfig,
+ isShowOenAi:lauoutConfig.isShowOenAi
}
)
+ this.refreshOptions()
}
+
const currentUserInfo = wx.getStorageSync('currentUserInfo')
if (currentUserInfo && currentUserInfo.nickName) {
console.log('currentUserInfo', currentUserInfo)
@@ -109,19 +147,113 @@ Component({
currentUserInfo: currentUserInfo
}
)
- this.setData({
- isShowOenAi: true
- })
}
},
moved: function () { },
+ // 销毁前
detached: function () {
- wx.setStorageSync('openAiOptions', this.data.chatObjConfig)
+ const key = app.wxProgramConfig.apiPageConfig.layoutConfig.storageKey
+ wx.setStorageSync(key, this.data.chatObjConfig)
+ this.getUserReadCount()
},
},
-
methods: {
+ previewImage(e){
+ console.log('click png',e)
+ const url=e.target.dataset.url
+ wx.previewImage({
+ current: url, // 当前显示图片的http链接
+ urls: [url] // 需要预览的图片http链接列表
+ })
+ },
+
+ // 获取用户
+ getUserInfo() {
+ const headers = { 'Content-Type': 'application/json;charset=UTF-8' }
+ const openId = wx.getStorageSync('currentOpenid')
+ const wxOpenId = openId && openId.openid
+ const params = {
+ wx_open_id: wxOpenId
+ }
+ const thisBack = this
+ wx.request({
+ url: this.data.baseCloudUrl + this.data.baseCloudgetUserPath,
+ headers: headers,
+ data: params,
+ method: 'POST',
+ success: (res => {
+ console.log('cloud res userInfo', res)
+ if (res && res.data && res.data) {
+ thisBack.setData({
+ // 默认十条消息
+ msgCount: res.data.data[0].send_msg_count || 10,
+ isVip: res.data.data[0].is_vip || 0
+ })
+ }
+ }),
+ fail: r => {
+ console.log('cloud r', r)
+ }
+ })
+ },
+ // 更新用户使用信息
+ updateUserInfo() {
+ const headers = { 'Content-Type': 'application/json;charset=UTF-8' }
+ const openId = wx.getStorageSync('currentOpenid')
+ const wxOpenId = openId && openId.openid
+ const params = {
+ wx_open_id: wxOpenId,
+ send_msg_count: this.data.msgCount
+ }
+ const thisBack = this
+ wx.request({
+ url: this.data.baseCloudUrl + this.data.baseCloudUpdateUserPath,
+ headers: headers,
+ data: params,
+ method: 'PUT',
+ success: (res => {
+ console.log('cloud res update', res)
+ }),
+ fail: r => {
+ console.log('cloud r', r)
+ }
+ })
+ },
+ // 获取用户使用次数
+ getUserReadCount() {
+ const headers = { 'Content-Type': 'application/json;charset=UTF-8' }
+ const openId = wx.getStorageSync('currentOpenid')
+ const wxOpenId = openId && openId.openid
+ const params = {
+ wx_open_id: wxOpenId
+ }
+ const thisBack = this
+ wx.request({
+ url: this.data.baseCloudUrl + this.data.baseCloudGetRecordCountPath,
+ headers: headers,
+ data: params,
+ method: 'POST',
+ success: (res => {
+ console.log('cloud res count', res)
+ if (res.data.code === 0) {
+ // 0
+ thisBack.setData({
+ msgCount: 0
+ })
+ } else {
+ thisBack.setData({
+ msgCount: res.data.data[0].send_msg_count
+ })
+ }
+ // 更新用户
+ thisBack.updateUserInfo()
+ }),
+ fail: r => {
+ console.log('cloud r', r)
+ }
+ })
+ },
upper(e) {
console.log('upper e', e)
},
@@ -129,12 +261,15 @@ Component({
console.log('lower e', e)
},
scroll(e) {
- console.log('scroll e', e)
+ // console.log('scroll e', e)
},
createOpenRecord(params) {
const headers = { 'Content-Type': 'application/json;charset=UTF-8' }
+ const openId = wx.getStorageSync('currentOpenid')
+ const wxOpenId = openId && openId.openid
+ params.wx_open_id = wxOpenId
wx.request({
- url: this.data.baseCloudUrl + this.data.baseCloudPath,
+ url: this.data.baseCloudUrl + this.data.baseCloudAddRecordPath,
headers: headers,
data: params,
method: 'POST',
@@ -146,6 +281,15 @@ Component({
}
})
},
+ upBtn() {
+ const index = 0
+ this.setData({
+ toView: `chat-mode${index}`
+ })
+ },
+ downBtn() {
+ this.scrollToBottom()
+ },
scrollToBottom() {
const index = this.data.chatObjConfig.option.length - 1
this.setData({
@@ -184,18 +328,7 @@ Component({
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 markdownText = app.changeMrkdownText(articleStr);
that.setData({
isLoading: false,
article: markdownText
@@ -210,13 +343,34 @@ Component({
mode: mode
})
},
+
+ refreshOptions() {
+ const option = this.data.chatObjConfig.option
+ const currentIndex = this.data.chatObjConfig.currentIndex
+ while (option && option.length > 100) {
+ option.shift()
+ }
+
+ const chatObjConfig = {
+ option: option,
+ currentIndex: currentIndex
+ }
+
+ this.setData(
+ {
+ chatObjConfig: chatObjConfig
+ }
+ )
+
+ },
+
bindKeyInput(e) {
this.setData({
searchOpenAiText: e.detail.value
})
},
reportAnswerData() {
- const data=this.data.chatObjConfig.option
+ const data = this.data.chatObjConfig.option
wx.setClipboardData({
data: JSON.stringify(data)
})
@@ -239,7 +393,53 @@ Component({
},
}))
},
+ pasteBtn(e) {
+ const thisBack = this
+ wx.getClipboardData({
+ success: (option) => {
+ console.log('option', option)
+ thisBack.setData({
+ searchOpenAiText: option.data
+ })
+ },
+ })
+ },
+ clearBtn() {
+ this.setData({
+ searchOpenAiText: ''
+ })
+ },
+ modalConfirm() {
+ const url=this.data.layoutConfig.wxInfoImg
+ wx.previewImage({
+ current: url, // 当前显示图片的http链接
+ urls: [url] // 需要预览的图片http链接列表
+ })
+ },
+ modalCandel() {
+ this.setData({
+ modalVisible: false
+ })
+ },
search(e) {
+ if (this.data.layoutConfig.permissionStatus) {
+ const isNotAllow = !(this.data.isVip || this.data.msgCount <= this.data.layoutConfig.limitMsgCount)
+ console.log('this.data.isVip', this.data.isVip)
+ console.log('this.data.msgCount', this.data.msgCount)
+ console.log('isNotAllow', isNotAllow)
+ if (isNotAllow) {
+ return this.setData({
+ modalVisible: true
+ })
+ // return wx.showModal({
+ // cancelColor: 'cancelColor',
+ // title: this.data.layoutConfig.permissionTitle,
+ // content: this.data.layoutConfig.permissionContent
+ // })
+ }
+
+ }
+
this.scrollToBottom()
if (!this.data.searchOpenAiText) {
wx.showModal({
@@ -270,33 +470,20 @@ Component({
console.log(res, 'res')
const data = res.data.data
const option = thisBack.data.chatObjConfig.option
- const currentIndex = thisBack.data.chatObjConfig.currentIndex
+ const errorMsg = thisBack.data.layoutConfig.errorMsg
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.question = params.text
- item.createTime = this.getCurrentTime()
- item.isEdit = false
- return true
- }
- return false
+ const answer = choices ? choices.map(choicesItem => { return choicesItem.text }).join('\n') : errorMsg
+ option.push({
+ question: params.text,
+ answer: answer,
+ answerMarkdown: app.changeMrkdownText(answer),
+ createTime: this.getCurrentTime(),
+ isEdit: false,
})
- // // 只保留30 条 缓存
- // if(option.length&&option.length>30){
- // option.shift()
- // }
const chatObjConfig = {
- option: option,
- currentIndex: currentIndex + 1
+ option: option
}
- // option.push({
- // question: '',
- // answer: '',
- // isEdit: true
- // })
+
thisBack.setData(
{
isLoading: false,
@@ -315,6 +502,8 @@ Component({
search_response: answer
})
}, 10)
+ console.log('thisBack.data.chatObjConfig.option', thisBack.data.chatObjConfig.option)
+ thisBack.refreshOptions()
},
fail: error => {
thisBack.setData({
@@ -326,4 +515,4 @@ Component({
})
}
}
-})
\ No newline at end of file
+})
diff --git a/miniprogram/pages/future/future.wxml b/miniprogram/pages/future/future.wxml
index 4dbe750bb13c886d673221d1ebb757b05597c29f..19fbaf6e2aaab2909c2d42795e330be826d49dab 100644
--- a/miniprogram/pages/future/future.wxml
+++ b/miniprogram/pages/future/future.wxml
@@ -1,14 +1,17 @@
-