提交 33851d29 编写于 作者: yma16's avatar yma16

feat: ai bot

上级 6cdb250f
// app.js // app.js
App({ App({
basePage:'pages/aiBot/aiBot',
homePageArticleId: 32, homePageArticleId: 32,
lifePageArricleId: 35, lifePageArricleId: 35,
wxProgramConfig: { wxProgramConfig: {
authorPageConfig: { authorPageConfig: {
cloudEmail: "1575057249@qq.com",
cloudPwd: "U2FsdGVkX1+jfEkF2OXTQ5iIG4mrYc5/TLOiIntyENU=",
title: "记忆碎片", title: "记忆碎片",
userImageUrl: 'https://yongma16.xyz/staticFile/common/img/logo.png', userImageUrl: 'https://yongma16.xyz/staticFile/common/img/aiTop.jpg',
loginTitle: '点击授权', loginTitle: '点击授权',
detailInfo: '关于:code笔记', detailInfo: '关于:code笔记',
nextPage: "/pages/home/home", nextPage: "/pages/home/home",
...@@ -13,6 +16,7 @@ App({ ...@@ -13,6 +16,7 @@ App({
userName: '月牙天冲', userName: '月牙天冲',
designPlaceholder: '自定义名称', designPlaceholder: '自定义名称',
joinTitle: '微信登录', joinTitle: '微信登录',
shopBtnTitle: '虚拟资产',
isOldVersion: false isOldVersion: false
}, },
homePageConfig: { homePageConfig: {
...@@ -61,7 +65,8 @@ App({ ...@@ -61,7 +65,8 @@ App({
} }
}, },
aboutPageConfig: { aboutPageConfig: {
articleId: 35 articleId: 35,
title:'个人信息'
} }
}, },
loginStatus: '', loginStatus: '',
...@@ -77,7 +82,8 @@ App({ ...@@ -77,7 +82,8 @@ App({
targetItem: {}, targetItem: {},
}, },
remoteConfig: { remoteConfig: {
baseUrl: 'https://yongma16.xyz' baseUrl: 'https://yongma16.xyz',
baseCloudUrl:'https://yongma16.xyz/cloudApi/api/',
}, },
// 引入`towxml3.0`解析方法 // 引入`towxml3.0`解析方法
towxml: require('/towxml/index'), towxml: require('/towxml/index'),
...@@ -166,7 +172,7 @@ App({ ...@@ -166,7 +172,7 @@ App({
if (res.data.data && res.data.data[0].option) { if (res.data.data && res.data.data[0].option) {
that.wxProgramConfig = JSON.parse(res.data.data[0].option) that.wxProgramConfig = JSON.parse(res.data.data[0].option)
wx.navigateTo({ wx.navigateTo({
url: 'pages/index/index', url: that.basePage,
success: function (res) { success: function (res) {
// 通过 eventChannel 向被打开页面传送数据 // 通过 eventChannel 向被打开页面传送数据
console.log('res', res) console.log('res', res)
...@@ -175,7 +181,7 @@ App({ ...@@ -175,7 +181,7 @@ App({
} }
else { else {
wx.navigateTo({ wx.navigateTo({
url: 'pages/index/index', url: that.basePage,
success: function (res) { success: function (res) {
// 通过 eventChannel 向被打开页面传送数据 // 通过 eventChannel 向被打开页面传送数据
console.log('res', res) console.log('res', res)
...@@ -189,7 +195,7 @@ App({ ...@@ -189,7 +195,7 @@ App({
success: (loadRes) => { console.log(loadRes) }, success: (loadRes) => { console.log(loadRes) },
}) })
wx.navigateTo({ wx.navigateTo({
url: 'pages/index/index', url: that.basePage,
success: function (res) { success: function (res) {
// 通过 eventChannel 向被打开页面传送数据 // 通过 eventChannel 向被打开页面传送数据
console.log('res', res) console.log('res', res)
...@@ -215,7 +221,7 @@ App({ ...@@ -215,7 +221,7 @@ App({
console.log('success') console.log('success')
} else { } else {
wx.navigateTo({ wx.navigateTo({
url: 'pages/index/index', url: this.basePage,
success: function (res) { success: function (res) {
// 通过 eventChannel 向被打开页面传送数据 // 通过 eventChannel 向被打开页面传送数据
console.log('res', res) console.log('res', res)
......
{ {
"pages": [ "pages": [
"pages/index/index", "pages/index/index",
"pages/home/home", "pages/home/home",
"pages/homeContent/homeContent", "pages/homeContent/homeContent",
"pages/blog/blog", "pages/blog/blog",
"pages/life/life", "pages/life/life",
"pages/future/future" "pages/future/future",
], "pages/shop/shop",
"window": { "pages/aiBot/aiBot"
"backgroundColor": "#F6F6F6", ],
"backgroundTextStyle": "light", "window": {
"navigationBarBackgroundColor": "#262626", "backgroundColor": "#F6F6F6",
"navigationBarTitleText": "yma16博客", "backgroundTextStyle": "light",
"navigationBarTextStyle": "white" "navigationBarBackgroundColor": "#262626",
}, "navigationBarTitleText": "yma16博客",
"sitemapLocation": "sitemap.json", "navigationBarTextStyle": "white"
"style": "v2" },
"sitemapLocation": "sitemap.json",
"style": "v2"
} }
\ No newline at end of file
// 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
{
"usingComponents": {
"towxml":"/towxml/towxml"
}
}
\ No newline at end of file
<view class="container-box">
<view class="chat-container" id="chat-container-id" style="width: 100%;">
<scroll-view scroll-y="true" class="scroll-answer" scroll-with-animation bindscrolltoupper="upper" bindscrolltolower="lower" bindscroll="scroll" scroll-into-view="{{toView}}" scroll-top="{{scrollTop}}" wx:if="{{ chatObjConfig.option&&chatObjConfig.option.length>0 }}">
<view wx:for="{{ chatObjConfig.option }}" wx:for-index="index" wx:for-item="item" wx:key="index" id="chat-mode{{index}}">
<view class="create-time">
{{item.createTime}}
</view>
<view class="form-request">
<view wx:if="{{!item.isEdit}}" class='questioned'>
<view style="display: flex;text-align: right;flex-direction:row-reverse;">
<view class="questioned-box-container">
<view class='questioned-box' style="text-align: left;">
{{item.question}}
</view>
<view class='questioned-box-poly'>
</view>
<view style="text-align: right;line-height: 50px;display: flex;max-height: 50px;">
<view class='form-request-user'>
<!-- {{currentUserInfo.nickName}} -->
<image class="user-image" src="{{currentUserInfo.avatarUrl}}"></image>
</view>
</view>
</view>
</view>
</view>
</view>
<view class="form-response" wx:if="{{!item.isEdit}}">
<view style="display: flex;">
<view style="line-height: 50px;">
<view class='form-response-user'>
<image class="ai-image" src="{{aiConfig.avatarUrl}}"></image>
<!-- {{aiConfig.nickName}} -->
</view>
</view>
<view class="form-response-box-poly">
</view>
<view class='form-response-box' style="overflow: auto;">
<towxml wx:key="index" nodes="{{item.answerMarkdown}}" style="position: relative;background: transparent;user-select: text;" />
</view>
</view>
<view style="display: flex;width: 100%;box-sizing: border-box;" wx:if="{{layoutConfig.isShowCopyBtn}}">
<view style="width: 70%;">
</view>
<view style="width: 30%;text-align: center;">
<button class="copy-btn" size="mini" bindtap="copyBtn" data-response=" {{item.answer}}">{{layoutConfig.copyText}}</button>
</view>
</view>
</view>
</view>
<view class="form-submit" wx:if="{{mode==='openAiUse'}}" style="width: 100%;">
</view>
</scroll-view>
<view wx:else class="scroll-answer">
<view class="create-time">
{{currenTime}}
</view>
<view style="display: flex;">
<view style="line-height: 50px;">
<view class='form-response-user'>
<image class="ai-image" src="{{aiConfig.avatarUrl}}"></image>
<!-- {{aiConfig.nickName}} -->
</view>
</view>
<view class="form-response-box-poly">
</view>
<view class="form-response-box" style="padding: 0 10px;">
{{layoutConfig.emptyText}}
</view>
</view>
</view>
<view class="bottom-box">
<view class='submit-input'>
<textarea class='send-input' bindinput="bindKeyInput" placeholder="{{layoutConfig.searchText}}" bindconfirm="search" value="{{searchOpenAiText}}" disabled="{{isLoading||isTruth}}" />
</view>
<view class='send-btn' type="primary" bindtap="search" loading="{{isLoading}}">{{layoutConfig.sendText}}</view>
</view>
</view>
</view>
\ No newline at end of file
/* pages/aiBot/aiBot.wxss */
.container-box{
position: relative;
width: 100vw;
height: 100vh;
background: rgb(245, 245, 245);
overflow: hidden;
box-sizing: border-box;
}
.container-box-article {
position: relative;
padding-top:0px;
width: 100%;
height: calc(100vh - 88px);
box-shadow: inset 5px 5px #262626;
overflow: auto;
user-select: text;
}
.scroll-answer {
height: calc(100vh - 100px);
}
.chat-container {
width: 100%;
height: 100vh;
overflow-y: auto;
overflow-x: hidden;
position: relative;
}
.paste-btn {
background: rgba(16, 116, 187);
color: #ffffff;
/* transform: scale(.7); */
border-radius: 5px;
}
.clear-btn {
background: rgba(16, 116, 187);
color: #ffffff;
/* transform: scale(.7); */
border-radius: 5px;
}
.paste-btn:hover {
border: none;
background: rgb(221, 0, 66);
}
.user-image-box {
width: 300px;
text-align: center;
align-items: center;
}
.user-image {
position: relative;
width: 15px;
height: 15px;
border-radius: 50%;
background-color: transparent;
background: transparent;
}
.ai-image {
position: relative;
width: 20px;
height: 20px;
border-radius: 50%;
}
.questioned-box-container {
display: flex;
}
.questioned-box {
position: relative;
max-width: calc(100vw - 90px);
height: auto;
overflow-x: auto;
background-color: rgb(255, 255, 255);
border-radius: 10px;
right: -5px;
padding: 0 10px;
z-index: 999;
color: #333;
font-family: PingFang SC, Lantinghei SC, Microsoft Yahei, Hiragino Sans GB, Microsoft Sans Serif, WenQuanYi Micro Hei, sans-serif;
font-weight: 300;
font-size: 32rpx;
user-select: text;
box-shadow: -5rpx 3rpx 1rpx -4rpx #c8c3c3;
}
.questioned-box-poly {
position: relative;
top: 15px;
width: 0;
height: 0;
border-radius: 5px;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 12px solid rgb(255, 255, 255);
box-shadow: 0rpx 0rpx 0rpx 0rpx #c8c3c3;
}
.clear-paste-btn{
width:70%;
display: flex;
}
.submit-input {
box-shadow: 0 2rpx 5rpx 5rpx #c8c3c3;
width: 70%;
}
.send-input {
height: 60px;
background: rgba(255, 255, 255, .8);
width: 100%;
height: 100px;
position: relative;
text-indent: 8px;
/* padding-left: 5px; */
color: rgb(0, 114, 221);
}
.send-btn::after{
position: absolute;
left:0;
top:0;
width: 100px;
height: 100%;
background-color: rgba(255, 255, 255, .8);
}
.up-down-btn{
width:30%;
}
.send-btn {
box-shadow: 0 2rpx 5rpx 5rpx #c8c3c3;
width: 30%;
background-color:rgba(16, 116, 187);
color: #ffffff;
height: 100px;
line-height: 100px;
/* border-radius: 10px 0 0 10px; */
text-align: center;
}
.empty-reponse-msg {
position: relative;
max-width: calc(100vw - 90px);
height: auto;
overflow-x: auto;
background-color: rgb(255, 255, 255);
border-radius: 10px;
left: -5px;
padding: 0 10px;
z-index: 999;
color: #333;
font-family: PingFang SC, Lantinghei SC, Microsoft Yahei, Hiragino Sans GB, Microsoft Sans Serif, WenQuanYi Micro Hei, sans-serif;
font-weight: 300;
font-size: 32rpx;
user-select: text;
}
.create-time {
width: 100%;
text-align: center;
color: rgb(255, 255, 255);
background: rgb(218, 218, 218);
margin: 5px auto;
box-shadow: inset 0 1rpx 2rpx 1rpx rgba(0, 0, 0, 0.2);
}
.form-response-user {
background-color: rgba(0, 72, 94, 0);
color: #fff;
}
.form-response-box-poly {
position: relative;
top: 15px;
width: 0;
height: 0;
border-radius: 5px;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right: 12px solid rgb(255, 255, 255);
}
.form-response-box {
position: relative;
max-width: calc(100vw - 50px);
/* word-break:keep-all; */
/* white-space: pre-wrap; */
white-space: pre-line;
height: auto;
overflow-x: auto;
background-color: rgb(255, 255, 255);
border-radius: 10px;
color: #333;
font-family: PingFang SC, Lantinghei SC, Microsoft Yahei, Hiragino Sans GB, Microsoft Sans Serif, WenQuanYi Micro Hei, sans-serif;
font-weight: 300;
font-size: 32rpx;
left: -5px;
box-sizing: content-box;
z-index: 999;
user-select: text;
box-shadow: 5rpx 3rpx 1rpx -4rpx #c8c3c3;
}
.form-request {
display: block;
width: 100%;
color: #fff;
background-color: rgba(37, 0, 97, 0);
line-height: 50px;
}
.form-response {
position: relative;
width: 100%;
margin-top: 10px;
display: block;
margin-bottom: 10px;
color: #fff;
background-color: rgba(0, 72, 94, 0);
box-sizing: border-box;
min-height: 60px;
}
.form-response-user {
background-color: rgba(0, 72, 94, 0);
color: #fff;
}
.form-request-user {
background-color: rgba(37, 0, 97, 0);
color: #fff;
}
.bottom-box {
display: flex;
width: 100%;
display: absolute;
bottom: 100px;
}
...@@ -99,17 +99,7 @@ Component({ ...@@ -99,17 +99,7 @@ Component({
* @param {*} title * @param {*} title
*/ */
setArticleNode(articleStr,title){ setArticleNode(articleStr,title){
const markdownText = app.towxml(articleStr,'markdown',{ const markdownText = app.changeMrkdownText(articleStr);
       theme:'light', //主题 dark 黑色,light白色,不填默认light
events:{ //为元素绑定的事件方法
tap:e => {
console.log('tap',e);
},
change:e => {
console.log('todo',e);
}
}
});
this.setData({ this.setData({
isLoading:false, isLoading:false,
article:markdownText, article:markdownText,
......
...@@ -34,15 +34,11 @@ Component({ ...@@ -34,15 +34,11 @@ Component({
articleId: baseArticleId, articleId: baseArticleId,
isShowOenAi: true, isShowOenAi: true,
baseUrl: 'https://yongma16.xyz/api/', baseUrl: 'https://yongma16.xyz/api/',
baseCloudUrl: 'https://yongma16.xyz/cloudApi/', baseCloudUrl: app.remoteConfig.baseCloudUrl,
baseCloudAddRecordPath: 'openAiRecord/add',
baseCloudUpdateUserPath: 'userModel/update',
baseCloudgetUserPath: 'userModel/info',
baseCloudGetRecordCountPath: 'openAiRecord/count',
path: 'article/blog/', path: 'article/blog/',
currentUserInfo: { currentUserInfo: {
nickName: '', nickName: '',
avatarUrl: '' avatarUrl: '',
}, },
aiConfig: { aiConfig: {
avatarUrl: 'https://yongma16.xyz/staticFile/common/img/aiTop.jpg', avatarUrl: 'https://yongma16.xyz/staticFile/common/img/aiTop.jpg',
...@@ -177,8 +173,10 @@ Component({ ...@@ -177,8 +173,10 @@ Component({
wx_open_id: wxOpenId wx_open_id: wxOpenId
} }
const thisBack = this const thisBack = this
const baseCloudUrl = this.data.baseCloudUrl
const baseInfoUrl = 'wechat/userinfo'
wx.request({ wx.request({
url: this.data.baseCloudUrl + this.data.baseCloudgetUserPath, url: baseCloudUrl + baseInfoUrl,
headers: headers, headers: headers,
data: params, data: params,
method: 'POST', method: 'POST',
...@@ -188,8 +186,8 @@ Component({ ...@@ -188,8 +186,8 @@ Component({
console.log('res.data__________',res.data) console.log('res.data__________',res.data)
thisBack.setData({ thisBack.setData({
// 默认十条消息 // 默认十条消息
msgCount: res.data.data.data[0].send_msg_count || 10, msgCount: res.data.data.data.use_count || 10,
isVip: res.data.data.data[0].is_vip || 0 isVip: res.data.data.data.is_vip || 0
}) })
} }
}), }),
...@@ -198,45 +196,26 @@ Component({ ...@@ -198,45 +196,26 @@ Component({
} }
}) })
}, },
// 更新用户使用信息 // 更新用户使用信息 这个过程koa处理
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() { getUserReadCount() {
const headers = { 'Content-Type': 'application/json;charset=UTF-8' } const headers = { 'Content-Type': 'application/json;charset=UTF-8' }
const openId = wx.getStorageSync('currentOpenid') const openId = wx.getStorageSync('currentOpenid')
const wxOpenId = openId && openId.openid const wxOpenId = openId && openId.openid
const params = { const params = {
wx_open_id: wxOpenId wx_openid: wxOpenId
} }
const thisBack = this const thisBack = this
const baseCloudUrl = this.data.baseCloudUrl
const baseInfoUrl = 'wechat/count'
wx.request({ wx.request({
url: this.data.baseCloudUrl + this.data.baseCloudGetRecordCountPath, url: baseCloudUrl + baseInfoUrl,
headers: headers, headers: headers,
data: params, data: params,
method: 'POST', method: 'POST',
success: (res => { success: (res => {
console.log('cloud res count', res) console.log('cloud res count', res)
console.log('res.data.data.use_count',res.data.data.use_count)
if (res.data.code === 0) { if (res.data.code === 0) {
// 0 // 0
thisBack.setData({ thisBack.setData({
...@@ -244,11 +223,11 @@ Component({ ...@@ -244,11 +223,11 @@ Component({
}) })
} else { } else {
thisBack.setData({ thisBack.setData({
msgCount: res.data.data[0].send_msg_count msgCount: res.data.data.use_count
}) })
} }
// 更新用户 // 更新用户
thisBack.updateUserInfo() // thisBack.updateUserInfo()
}), }),
fail: r => { fail: r => {
console.log('cloud r', r) console.log('cloud r', r)
...@@ -268,10 +247,12 @@ Component({ ...@@ -268,10 +247,12 @@ Component({
const headers = { 'Content-Type': 'application/json;charset=UTF-8' } const headers = { 'Content-Type': 'application/json;charset=UTF-8' }
const openId = wx.getStorageSync('currentOpenid') const openId = wx.getStorageSync('currentOpenid')
const wxOpenId = openId && openId.openid const wxOpenId = openId && openId.openid
params.wx_open_id = wxOpenId params.wx_openid = wxOpenId
const thisBack=this const thisBack=this
const baseCloudUrl = this.data.baseCloudUrl
const baseInfoUrl = 'wechat/addcontent'
wx.request({ wx.request({
url: this.data.baseCloudUrl + this.data.baseCloudAddRecordPath, url: baseCloudUrl + baseInfoUrl,
headers: headers, headers: headers,
data: params, data: params,
method: 'POST', method: 'POST',
...@@ -499,10 +480,8 @@ Component({ ...@@ -499,10 +480,8 @@ Component({
resolve(res) resolve(res)
setTimeout(() => { setTimeout(() => {
thisBack.createOpenRecord({ thisBack.createOpenRecord({
wx_name: thisBack.data.currentUserInfo.nickName, question_content: params.text,
wx_img: thisBack.data.currentUserInfo.avatarUrl, anwser_content: answer
search_text: params.text,
search_response: answer
}) })
}, 10) }, 10)
console.log('thisBack.data.chatObjConfig.option', thisBack.data.chatObjConfig.option) console.log('thisBack.data.chatObjConfig.option', thisBack.data.chatObjConfig.option)
......
...@@ -86,7 +86,7 @@ button { ...@@ -86,7 +86,7 @@ button {
color: rgb(255, 255, 255); color: rgb(255, 255, 255);
background: rgb(218, 218, 218); background: rgb(218, 218, 218);
margin: 5px auto; margin: 5px auto;
box-shadow:inset 0 1rpx 2rpx 1rpx rgba(0,0,0,0.2); box-shadow: inset 0 1rpx 2rpx 1rpx rgba(0, 0, 0, 0.2);
} }
.header-box { .header-box {
...@@ -183,7 +183,7 @@ button { ...@@ -183,7 +183,7 @@ button {
.container-box-article { .container-box-article {
position: relative; position: relative;
padding-top:0px; padding-top: 0px;
width: 100%; width: 100%;
height: calc(100vh - 88px); height: calc(100vh - 88px);
box-shadow: inset 5px 5px #262626; box-shadow: inset 5px 5px #262626;
...@@ -275,10 +275,12 @@ button { ...@@ -275,10 +275,12 @@ button {
border-left: 12px solid rgb(255, 255, 255); border-left: 12px solid rgb(255, 255, 255);
box-shadow: 0rpx 0rpx 0rpx 0rpx #c8c3c3; box-shadow: 0rpx 0rpx 0rpx 0rpx #c8c3c3;
} }
.clear-paste-btn{
width:70%; .clear-paste-btn {
width: 70%;
display: flex; display: flex;
} }
.submit-input { .submit-input {
box-shadow: 0 2rpx 5rpx 5rpx #c8c3c3; box-shadow: 0 2rpx 5rpx 5rpx #c8c3c3;
width: 70%; width: 70%;
...@@ -294,23 +296,24 @@ button { ...@@ -294,23 +296,24 @@ button {
/* padding-left: 5px; */ /* padding-left: 5px; */
color: rgb(0, 114, 221); color: rgb(0, 114, 221);
} }
.send-btn::after{
.send-btn::after {
position: absolute; position: absolute;
left:0; left: 0;
top:0; top: 0;
width: 100px; width: 100px;
height: 100%; height: 100%;
background-color: rgba(255, 255, 255, .8); background-color: rgba(255, 255, 255, .8);
} }
.up-down-btn{ .up-down-btn {
width:30%; width: 30%;
} }
.send-btn { .send-btn {
box-shadow: 0 2rpx 5rpx 5rpx #c8c3c3; box-shadow: 0 2rpx 5rpx 5rpx #c8c3c3;
width: 30%; width: 30%;
background-color:rgba(16, 116, 187); background-color: rgba(16, 116, 187);
height: 100px; height: 100px;
line-height: 100px; line-height: 100px;
/* border-radius: 10px 0 0 10px; */ /* border-radius: 10px 0 0 10px; */
...@@ -352,7 +355,7 @@ button { ...@@ -352,7 +355,7 @@ button {
box-sizing: content-box; box-sizing: content-box;
z-index: 999; z-index: 999;
user-select: text; user-select: text;
box-shadow:5rpx 3rpx 1rpx -4rpx #c8c3c3; box-shadow: 5rpx 3rpx 1rpx -4rpx #c8c3c3;
} }
.form-response-box-poly { .form-response-box-poly {
......
...@@ -4,7 +4,10 @@ const app = getApp() ...@@ -4,7 +4,10 @@ const app = getApp()
Page({ Page({
data: { data: {
baseUrl: app.remoteConfig.baseUrl, baseUrl: app.remoteConfig.baseUrl,
baseCloudUrl: app.remoteConfig.baseCloudUrl,
baseLoginCloudPath: 'userModel/register', baseLoginCloudPath: 'userModel/register',
botBtnTitle: "图片生成",
shopBtnTitle: '虚拟资产',
detailInfo: '关于:code笔记', detailInfo: '关于:code笔记',
title: "yma16博客", title: "yma16博客",
userImageUrl: "https://yongma16.xyz/staticFile/common/img/aiTop.jpg", userImageUrl: "https://yongma16.xyz/staticFile/common/img/aiTop.jpg",
...@@ -18,7 +21,9 @@ Page({ ...@@ -18,7 +21,9 @@ Page({
hasUserInfo: false, hasUserInfo: false,
isloading: true, isloading: true,
isOldVersion: false, isOldVersion: false,
isShowBottom: true isShowBottom: true,
loginErrorTitle: '',
loginErrorContent: ''
}, },
getUserInfoBtn: function (info) { getUserInfoBtn: function (info) {
wx.showLoading({ wx.showLoading({
...@@ -26,7 +31,10 @@ Page({ ...@@ -26,7 +31,10 @@ Page({
}); });
console.log('userinfo', info) console.log('userinfo', info)
if (info && info.detail) { if (info && info.detail) {
const rowData = info.detail.rawData ? JSON.parse(info.detail.rawData) : { nickName: '未授权用户', avatarUrl: '' } const rowData = info.detail.rawData ? JSON.parse(info.detail.rawData) : {
nickName: '未授权用户',
avatarUrl: ''
}
this.setData({ this.setData({
userImageUrl: rowData.avatarUrl, userImageUrl: rowData.avatarUrl,
userName: rowData.nickName, userName: rowData.nickName,
...@@ -38,16 +46,50 @@ Page({ ...@@ -38,16 +46,50 @@ Page({
wx.hideLoading(); wx.hideLoading();
}, },
bindKeyInput(e) { bindKeyInput(e) {
const { value } = e.detail const {
value
} = e.detail
console.log('val', value) console.log('val', value)
this.setData({ this.setData({
userName: value userName: value
}) })
}, },
clickBotBtn() {
wx.navigateTo({
url: '/pages/aiBot/aiBot'
})
},
// 进入虚拟资产
clickShopBtn() {
console.log('跳转')
// const thisBack = this
wx.navigateTo({
url: '/pages/shop/shop',
// events: {
// // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
// acceptDataFromOpenedPage: function (data) {
// console.log('acceptDataFromOpenedPage data', data)
// },
// someEvent: function (data) {
// console.log('someEvent data', data)
// }
// },
// success: function (res) {
// console.log('res jump', res)
// // 通过 eventChannel 向被打开页面传送数据
// res.eventChannel.emit('setHomePageData', {
// userInfo: thisBack.data.userInfo,
// isShowBottom: thisBack.data.isShowBottom
// })
// }
})
},
// 头像选择 // 头像选择
onChooseAvatar(e) { onChooseAvatar(e) {
console.log('e', e) console.log('e', e)
const { avatarUrl } = e.detail const {
avatarUrl
} = e.detail
this.setData({ this.setData({
userImageUrl: avatarUrl, userImageUrl: avatarUrl,
}) })
...@@ -101,14 +143,17 @@ Page({ ...@@ -101,14 +143,17 @@ Page({
loginSpringCloud() { loginSpringCloud() {
const openId = wx.getStorageSync('currentOpenid') const openId = wx.getStorageSync('currentOpenid')
const wxOpenId = openId && openId.openid const wxOpenId = openId && openId.openid
const headers = { 'Content-Type': 'application/json;charset=UTF-8' } const headers = {
'Content-Type': 'application/json;charset=UTF-8'
}
const params = { const params = {
wx_open_id: wxOpenId, wx_openid: wxOpenId,
wx_name: this.data.userName, wx_name: this.data.userName,
wx_img: this.data.userImageUrl wx_img: this.data.userImageUrl
} }
const baseCloudUrl = 'https://yongma16.xyz/cloudApi/' const baseCloudUrl = this.data.baseCloudUrl
const baseLoginCloudPath = 'userModel/register' const baseLoginCloudPath = 'wechat/register'
console.log('注册', params)
wx.request({ wx.request({
url: baseCloudUrl + baseLoginCloudPath, url: baseCloudUrl + baseLoginCloudPath,
headers: headers, headers: headers,
...@@ -200,8 +245,10 @@ Page({ ...@@ -200,8 +245,10 @@ Page({
}) })
}, },
onLoad: function (options) { onLoad: function (options) {
console.log('index page')
console.log('option', options) console.log('option', options)
const authorPageConfig = app.wxProgramConfig.authorPageConfig const authorPageConfig = app.wxProgramConfig.authorPageConfig
console.log('authorPageConfig', authorPageConfig)
this.setData({ this.setData({
detailInfo: authorPageConfig.detailInfo, detailInfo: authorPageConfig.detailInfo,
title: authorPageConfig.title, title: authorPageConfig.title,
...@@ -213,6 +260,7 @@ Page({ ...@@ -213,6 +260,7 @@ Page({
designPlaceholder: authorPageConfig.designPlaceholder, designPlaceholder: authorPageConfig.designPlaceholder,
isOldVersion: authorPageConfig.isOldVersion, isOldVersion: authorPageConfig.isOldVersion,
joinTitle: authorPageConfig.joinTitle, joinTitle: authorPageConfig.joinTitle,
shopBtnTitle: authorPageConfig.shopBtnTitle,
isShowBottom: authorPageConfig.isShowBottom, isShowBottom: authorPageConfig.isShowBottom,
loginErrorTitle: authorPageConfig.loginErrorTitle, loginErrorTitle: authorPageConfig.loginErrorTitle,
loginErrorContent: authorPageConfig.loginErrorContent loginErrorContent: authorPageConfig.loginErrorContent
...@@ -247,4 +295,4 @@ Page({ ...@@ -247,4 +295,4 @@ Page({
onResize: function () { onResize: function () {
// 页面尺寸变化时执行 // 页面尺寸变化时执行
} }
}); });
\ No newline at end of file
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
<!-- <view style="width: 30%;text-align: right;"> <!-- <view style="width: 30%;text-align: right;">
{{userPrefix}} {{userPrefix}}
</view> --> </view> -->
<view style="width:100%;text-align: center;"> <view style="width:100%;text-align: center;margin:0 30px;">
<input type="nickname" class="weui-input" value="{{userName}}" bindinput="bindKeyInput" placeholder-style="color: #fff" style="width: 100%;border-bottom: 1px solid #ffffff;" placeholder="{{designPlaceholder}}" /> <input type="nickname" class="weui-input" value="{{userName}}" bindinput="bindKeyInput" placeholder-style="color: #fff" style="width: 100%;border-bottom: 1px solid #ffffff;" placeholder="{{designPlaceholder}}" />
</view> </view>
</view> </view>
...@@ -35,6 +35,12 @@ ...@@ -35,6 +35,12 @@
<view class="login-container"> <view class="login-container">
<button type="primary" plain="true" bindtap="getUserProfile" class="user-login" bindgetuserinfo="getUserInfoBtn" wx:if="{{isOldVersion}}">{{loginTitle}}</button> <button type="primary" plain="true" bindtap="getUserProfile" class="user-login" bindgetuserinfo="getUserInfoBtn" wx:if="{{isOldVersion}}">{{loginTitle}}</button>
<button type="primary" plain="true" bindtap="getUserProfile" bindtap="joinProfile" class="user-login" wx:else>{{joinTitle}}</button> <button type="primary" plain="true" bindtap="getUserProfile" bindtap="joinProfile" class="user-login" wx:else>{{joinTitle}}</button>
<button type="primary" plain="true"
bindtap="clickBotBtn" class="bot-btn" >{{botBtnTitle}}</button>
<button type="primary" plain="true"
bindtap="clickShopBtn" class="shop-btn" >{{shopBtnTitle}}</button>
</view> </view>
</view> </view>
<view class="loading-container"> <view class="loading-container">
......
...@@ -21,9 +21,7 @@ page { ...@@ -21,9 +21,7 @@ page {
} }
.login-container{ .login-container{
position: absolute; position: relative;
top:50%;
transform: translateY(50%);
} }
.code-container{ .code-container{
...@@ -34,6 +32,22 @@ page { ...@@ -34,6 +32,22 @@ page {
.user-login { .user-login {
margin-top: 10px;
width:120px !important;
color: #fff !important;
border-color: #fff !important;
}
.shop-btn{
margin-top: 160px;
width:120px !important;
color: #fff !important;
border-color: #fff !important;
}
.bot-btn{
margin-top: 120px;
width:120px !important; width:120px !important;
color: #fff !important; color: #fff !important;
border-color: #fff !important; border-color: #fff !important;
...@@ -49,14 +63,14 @@ page { ...@@ -49,14 +63,14 @@ page {
.user-image-box { .user-image-box {
width: 200px; width: 200px;
height: 140px; height: 80px;
text-align: center; text-align: center;
align-items: center; align-items: center;
} }
.user-image { .user-image {
width: 100px; width: 30px;
height: 100px; height: 30px;
border-radius: 50%; border-radius: 50%;
border: 2px solid #fff; border: 2px solid #fff;
} }
......
// pages/shop.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
password: app.remoteConfig.cloudPwd || "U2FsdGVkX1+jfEkF2OXTQ5iIG4mrYc5/TLOiIntyENU=",
username: app.remoteConfig.cloudEmail || "1575057249@qq.com",
baseCloudUrl: app.remoteConfig.baseCloudUrl,
token: '',
name: '',
page: 1,
pageSize: 99,
productList: []
},
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()
that.getProductList()
}),
fail: r => {
console.log('cloud r', r)
wx.hideLoading()
}
})
},
previewImage(e){
console.log('click png',e)
const url=e.target.dataset.url
wx.previewImage({
current: url, // 当前显示图片的http链接
urls: [url] // 需要预览的图片http链接列表
})
},
getRenderSrc(id) {
return `${this.data.baseCloudUrl}media/render?id=${id}`
},
getProductList() {
const that = this
wx.showLoading({
title: 'get list loading',
});
wx.request({
url: this.data.baseCloudUrl + '/product/list',
method: 'POST',
header: {
Authorization: `bearer ${this.data.token}`
},
data: {
name: '',
page: this.data.page,
pageSize: this.data.pageSize,
},
success: (res => {
that.setData({
productList: res.data.data.map(item => {
return {
...item,
imgSrc: item.img_id?that.getRenderSrc(item.img_id):'',
mvSrc: item.mov_id?that.getRenderSrc(item.mov_id):'',
mode: 'scaleToFill',
}
})
})
wx.hideLoading()
}),
fail: r => {
console.log('cloud r', r)
wx.hideLoading()
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getUserToken()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<!--pages/shop.wxml-->
<view class='container'>
<block wx:for="{{productList}}" wx:key="*this">
<view class="list-item">
<view class='item-title'>{{item.title}}</view>
<view class='item-des'>{{item.description}}</view>
<view class='item-box'>
<image class='item-img' src="{{item.imgSrc}}" data-url="{{item.imgSrc}}" bindtap="previewImage" mode="{{item.mode}}">
</image>
</view>
<view class='item-content'>{{item.content}}</view>
<!-- <view class='item-box' wx:if="{{item.mvSrc}}">
视频讲解
<video class='item-mv' src="{{item.mvSrc}}" enable-danmu danmu-btn show-center-play-btn='{{false}}' show-play-btn="{{true}}" controls picture-in-picture-mode="{{['push', 'pop']}}"></video>
</view> -->
</view>
</block>
</view>
\ No newline at end of file
/* pages/shop.wxss */
.list-box {
width: 100%;
height: 100%;
color: #262626;
padding: 10px;
}
.container {
padding: 0;
margin: 0;
color: #333333;
background: #262626;
}
.list-item{
border:1px solid #dcdcdc;
margin: 5px;
padding: 2px;
text-indent: 12px;
width: 90%;
height: 250px;
background: #ffffff;
border-radius: 10px;
box-shadow: 0 10px 15px rgba(255,255,255,.6);
}
.item-title {
font-weight: bold;
}
.item-content {
color: #333333;
}
.item-box {
padding: 5px 0;
margin:2px 0;
width: 100%;
text-align: center;
text-indent: 0;
}
.item-img{
max-height: 150px;
width: 80%;
}
\ No newline at end of file
{
"name": "yma16_program",
"version": "1.0.0",
"description": "- [云开发文档](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html) ### 云开发小程序",
"main": ".eslintrc.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@gitcode.net:qq_38870145/yma16_miniprogram.git"
},
"author": "yma16",
"license": "ISC"
}
{ {
"description": "项目配置文件", "description": "项目配置文件",
"packOptions": {
"ignore": [],
"include": []
},
"setting": { "setting": {
"urlCheck": true, "urlCheck": true,
"es6": true, "es6": true,
...@@ -24,8 +20,6 @@ ...@@ -24,8 +20,6 @@
"compileHotReLoad": true, "compileHotReLoad": true,
"lazyloadPlaceholderEnable": false, "lazyloadPlaceholderEnable": false,
"useMultiFrameRuntime": true, "useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"babelSetting": { "babelSetting": {
"ignore": [], "ignore": [],
"disablePlugins": [], "disablePlugins": [],
...@@ -41,12 +35,10 @@ ...@@ -41,12 +35,10 @@
"minifyWXML": true, "minifyWXML": true,
"showES6CompileOption": false, "showES6CompileOption": false,
"useCompilerPlugins": false, "useCompilerPlugins": false,
"condition": false "condition": false,
"ignoreUploadUnusedFiles": true
}, },
"compileType": "miniprogram", "compileType": "miniprogram",
"libVersion": "2.27.0",
"appid": "wx373f33f993c688d1",
"projectname": "yma16_program",
"miniprogramRoot": "miniprogram/", "miniprogramRoot": "miniprogram/",
"cloudfunctionRoot": "cloudfunctions/", "cloudfunctionRoot": "cloudfunctions/",
"cloudfunctionTemplateRoot": "cloudfunctionTemplate/", "cloudfunctionTemplateRoot": "cloudfunctionTemplate/",
...@@ -75,5 +67,10 @@ ...@@ -75,5 +67,10 @@
"editorSetting": { "editorSetting": {
"tabIndent": "insertSpaces", "tabIndent": "insertSpaces",
"tabSize": 4 "tabSize": 4
} },
"packOptions": {
"ignore": [],
"include": []
},
"appid": "wx373f33f993c688d1"
} }
\ No newline at end of file
{ {
"setting": { "setting": {
"compileHotReLoad": true "compileHotReLoad": true,
"urlCheck": false
}, },
"condition": { "condition": {
"miniprogram": { "miniprogram": {
"list": [ "list": [
{ {
"name": "pages/getOpenId/index", "name": "yma16博客",
"pathName": "pages/getOpenId/index", "pathName": "pages/index/index",
"query": "", "query": "",
"scene": null "scene": null
} }
...@@ -15,5 +16,6 @@ ...@@ -15,5 +16,6 @@
} }
}, },
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "yma16_program" "projectname": "yma16_program",
"libVersion": "2.25.3"
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册