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

perf:动态配置页面文字和页面跳转

上级 37fe5428
......@@ -4,4 +4,4 @@
### 云开发小程序
# 接入markdown
\ No newline at end of file
# 接入markdown博客
\ No newline at end of file
// 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'),
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.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.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.info('用户授权', res)
this.setData({
globalData:{userInfo: res.userInfo,hasUserInfo: true},
})
wx.setStorageSync('currentUserInfo', res.userInfo)
}
})
// 用户登录
let host = "https://example.com/onLogin"
const that = this
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)
// }
that.globalData.loginStatus = res
}
})
let setting = null;
wx.getSetting({
success(res) {
setting = res
console.log('res', res)
console.log('res set', res)
that.globalData.setting = res
}
})
this.globalData = { setting: setting };
console.log('onLaunch', options)
}
},
onShow(options) {
......
......@@ -11,7 +11,7 @@
"backgroundColor": "#F6F6F6",
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#262626",
"navigationBarTitleText": "阳光罐里的日记",
"navigationBarTitleText": "yma16博客",
"navigationBarTextStyle": "white"
},
"sitemapLocation": "sitemap.json",
......
// 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({
/**
* 继承父级样式
*/
......@@ -15,72 +16,96 @@ Component({
// 用户信息
userInfo: {
type: Object,
value: ()=>{
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&&currentUserInfo.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
})
}
......@@ -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);
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);
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()
......
{
"usingComponents": {
"geoMap":"/components/visualComponent/geoMap/geoMap",
"lineChart":"/components/visualComponent/lineChart/lineChart",
"blockInfo":"/components/base/blockInfo/blockInfo",
"towxml":"/towxml/towxml"
}
}
......@@ -10,31 +10,34 @@
</view> -->
<view class="form-container-introduce" wx:if="{{mode==='introduce'}}">
<view class="header-box" style="display: flex;">
<view style="width: 50%;" wx:if="{{isShowOenAi}}">
<button style="width: 100%;" type="primary" style="background: rgb(8, 183, 252);" loading="{{isLoading}}">api介绍</button>
</view>
<view style="width: 100%;" wx:else>
<button style="width: 100%;" type="primary" style="background: rgb(8, 183, 252);" loading="{{isLoading}}">api介绍</button>
<view style="width: {{isShowOenAi? '50%':'100%'}}">
<button style="width: 100%;" type="primary" style="background: rgb(8, 183, 252);" loading="{{isLoading}}">{{layoutConfig.introduceText}}</button>
</view>
<view style="width:50%" wx:if="{{isShowOenAi}}">
<button style="width: 100%;" type="primary" style="background: rgb(0, 114, 221);" bindtap="changeMode" loading="{{isLoading}}" data-mode='openAiUse'>使用</button>
<button style="width: 100%;" type="primary" style="background: rgb(0, 114, 221);" bindtap="changeMode" loading="{{isLoading}}" data-mode='openAiUse'>{{layoutConfig.useText}}</button>
</view>
</view>
<view class="loading" wx:if="{{isLoading}}">
<view class="loader-child" />
<view class="loader-child" />
<view class="loader-child" />
</view>
<view class="container-box-article">
<towxml nodes="{{article}}"/>
<towxml nodes="{{article}}" />
</view>
</view>
<view class="form-container-api" wx:if="{{mode==='openAiUse'}}">
<view>
<button style="width: 100%;" type="primary" bindtap="changeMode" loading="{{isLoading}}" data-mode='introduce'>返回介绍</button>
<button style="width: 100%;background-color: #0758c1;" type="primary" bindtap="changeMode" loading="{{isLoading}}" data-mode='introduce'>{{layoutConfig.returnText}}</button>
</view>
<view class="chat-container" id="chat-container-id">
<view wx:for="{{ chatObjConfig.option }}" wx:for-index="index" wx:for-item="item" wx:key="*this">
<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}}">
<view wx:for="{{ chatObjConfig.option }}" wx:for-index="index" wx:for-item="item" wx:key="*this" id="chat-mode{{index}}">
<view class="form-request">
<view wx:if="{{item.isEdit}}">
<image class="user-image" src="{{currentUserInfo.avatarUrl}}"></image>
<view style="display: inline;">({{currentUserInfo.nickName}}): </view>
<input bindinput="bindKeyInput" style="display: inline;" placeholder="关键词查询" data-column-index="{{index}}" disabled="{{isLoading}}" />
<view style="display: inline;">({{currentUserInfo.nickName}}):$ </view>
<input bindinput="bindKeyInput" style="display: inline;" placeholder="{{layoutConfig.searchText}}" data-column-index="{{index}}" disabled="{{isLoading}}" />
</view>
<view wx:else class='questioned'>
<view>
......@@ -43,23 +46,22 @@
</view>
</view>
<view class="form-response">
<view class='questioned'>
<image class="ai-image" src="{{aiConfig.avatarUrl}}"></image>
(openai):$ {{item.answer}}
</view>
(openai):$ {{item.answer}}
</view>
</view>
<view class="form-submit" wx:if="{{mode==='openAiUse'}}">
<button style="width: 100%;" type="primary" bindtap="search" loading="{{isLoading}}">发送</button>
</view>
<view class="form-submit" wx:if="{{mode==='openAiUse'}}" style="width: 100%;">
</view>
</scroll-view>
<button style="width: 100%;;background-color: #0758c1;" type="primary" bindtap="search" loading="{{isLoading}}">{{layoutConfig.sendText}}</button>
</view>
<view class="loading" wx:if="{{isLoading}}">
<view class="loader-child" />
<view class="loader-child" />
<view class="loader-child" />
</view>
<view class="content-container" wx:if="{{!isLoading}}">
<!-- <geoMap wx:if="{{btnType==='map'}}" ></geoMap>
......
......@@ -3,10 +3,13 @@
position: relative;
width: 100vw;
height: 100vh;
background: linear-gradient(to right, rgba(1, 41, 116, 0.1) 1px, transparent 1px), linear-gradient(to bottom, rgba(1, 41, 116, 0.1) 1px, transparent 1px);
/* background: linear-gradient(to right, rgba(1, 41, 116, 0.1) 1px, transparent 1px), linear-gradient(to bottom, rgba(1, 41, 116, 0.1) 1px, transparent 1px);
background-repeat: repeat;
background-size: 10px 10px;
border: 1px solid #01c4ff;
border: 1px solid #01c4ff; */
background-image: url('https://yongma16.xyz/staticFile/common/img/aiBg.jpg');
background-repeat: no-repeat;
background-size: cover;
overflow: hidden;
box-sizing: border-box;
}
......@@ -101,9 +104,8 @@ button {
display: block;
width: 100%;
color: #07c160;
background-color: rgb(37, 0, 97);
background-color: rgba(37, 0, 97,.9);
line-height: 50px;
padding: 5px;
}
.form-response {
......@@ -113,7 +115,9 @@ button {
display: block;
margin-bottom: 10px;
color: #07c160;
background-color: rgb(0, 72, 94);
background-color: rgba(0, 72, 94,.9);
box-sizing: border-box;
min-height: 60px;
}
.form-class-submit {
......@@ -135,11 +139,13 @@ button {
height: calc(100vh - 100px);
overflow: auto;
}
.scroll-answer{
height: calc(100vh - 90px);
}
.chat-container {
margin-top: 10px;
width: 100%;
height: calc(100vh - 120px);
height: calc(100vh - 40px);
overflow-y: auto;
overflow-x: hidden;
position: relative;
......@@ -165,3 +171,13 @@ button {
height: 20px;
border-radius: 50%;
}
/* .loader-child:nth-of-type(1) {
border-bottom: 3px solid #ffffff;
}
.loader-child:nth-of-type(2) {
border-right: 3px solid #ffffff;
}
.loader-child:nth-of-type(3) {
border-right: 3px solid #ffffff;
} */
\ No newline at end of file
......@@ -7,14 +7,12 @@ Page({
* 页面的初始数据
*/
data: {
toView: '',
title: 'header',
userInfo: {},
content: '我是父组件的content',
footContent: "bottomContent",
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' }
],
swiperConfig: {
indicatorDots: true,
......@@ -32,7 +30,15 @@ Page({
baseUrl: 'https://yongma16.xyz/api/',
path: 'article/index/',
currentArticleId: 0,
currentArticleTitle: ''
currentArticleTitle: '',
isShowBottom: true,
bottomStyleConfig: {
tabMenuText: '记忆碎片',
homePageText: '主页',
blogText: '博客',
apiText: 'openai',
aboutText: '关于'
}
},
// 监听
watch: {
......@@ -40,35 +46,42 @@ Page({
console.log('监听', newVal, oldVal)
}
},
updateBottomNavigation(e) {
console.log('val home', e)
this.setData({
isShowBottom: e.detail
})
},
/**
* 用户信息配置
* @param {Object} userInfo
*/
setCurrentUserInfo(userInfo){
console.log('事件触发userInfo',userInfo)
setCurrentUserInfo(userInfo) {
console.log('事件触发userInfo', userInfo)
this.setData({
userInfo:userInfo
userInfo: userInfo
})
},
/**
* 获取文章
*/
clickBlogTitleBtn(e) {
const {id,title}=e.currentTarget.dataset
const { id, title } = e.currentTarget.dataset
this.setData({
currentArticleId:id,
currentArticleTitle:title
currentArticleId: id,
currentArticleTitle: title
})
this.getRemoteArticleById(id)
},
initHomeComponent(){
const articleObjId=this.data.headBackground[0].articleId
initHomeComponent() {
const articleObjId = this.data.headBackground[0].articleId
this.updateHomeContent(articleObjId)
},
/**
* 更新
* @param {*} articleObjId
*/
updateHomeContent(articleObjId){
updateHomeContent(articleObjId) {
this.triggerClearHomeContent()
this.triggerGetHomeContent(articleObjId)
},
......@@ -76,25 +89,29 @@ Page({
* 卡片变动修改内容
* @param {*} e
*/
swiperChange(e){
const index=e.detail.current
const articleObjId=this.data.headBackground[index].articleId
swiperChange(e) {
const index = e.detail.current
const articleObjId = this.data.headBackground[index].articleId
this.updateHomeContent(articleObjId)
},
/**
* 触发子组件跟新id
*/
triggerGetHomeContent(id){
triggerGetHomeContent(id) {
const homeComponent = this.selectComponent('#home-content-id')
if (homeComponent && homeComponent.getRemoteArticle) {
homeComponent.getRemoteArticle(id)
}
},
/**
* 触发子组件删除article
*/
triggerClearHomeContent(){
triggerClearHomeContent() {
const homeComponent = this.selectComponent('#home-content-id')
if (homeComponent && homeComponent.clearArticle) {
homeComponent.clearArticle()
}
},
/**
......@@ -102,13 +119,13 @@ Page({
* @param {*} id
*/
getRemoteArticleById() {
const paramId=this.data.currentArticleId;
const paramId = this.data.currentArticleId;
const blogComponent = this.selectComponent('#blog-id')
blogComponent.setLoading(true)
blogComponent.clearArticleNode()
const baseUrl = this.data.baseUrl
const path = this.data.path
const that=this
const that = this
const headers = { 'Content-Type': 'application/json;charset=UTF-8' }
const params = {
value: paramId
......@@ -121,8 +138,8 @@ Page({
success: (res) => {
const data = res.data
const articleStr = data && data.article[0]
const title=that.data.currentArticleTitle
blogComponent.setArticleNode(articleStr,title)
const title = that.data.currentArticleTitle
blogComponent.setArticleNode(articleStr, title)
}
});
},
......@@ -190,7 +207,23 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// this.initHomeComponent();
const eventChannel = this.getOpenerEventChannel()
if (eventChannel.emit) {
eventChannel.emit('acceptDataFromOpenedPage', { data: 'test' });
eventChannel.emit('someEvent', { data: 'test' });
}
if (eventChannel.on) {
// 监听 acceptDataFromOpenerPage 事件,获取上一页面通过 eventChannel 传送到当前页面的数据
eventChannel.on('setHomePageData', function (data) {
console.log('setHomePageData', data)
})
}
this.setData({
headBackground: app.wxProgramConfig.homePageConfig.headBackground,
bottomBtn: app.wxProgramConfig.homePageConfig.bottomBtn,
bottomStyleConfig: app.wxProgramConfig.homePageConfig.bottomStyleConfig
})
this.initHomeComponent();
},
/**
......
......@@ -7,7 +7,7 @@
<view class="container-menu" wx:if="{{menuIsShow}}">
<view class="arrow-right" bindtap="menuSwitch"></view>
<view class="btn-ul" style="margin-top: 10px;font-weight: bold;position: absolute;">
记忆碎片</view>
{{bottomStyleConfig.tabMenuText}}</view>
<view class='menu-box' style="margin-top: 40px;">
<block wx:for="{{titleObj}}" wx:key="*this">
<view class="blog-title {{currentArticleId===item.id? 'title-actived':''}}" bindtap="clickBlogTitleBtn" data-title="{{item.title}}" data-id="{{item.id}}">{{item.title}}</view>
......@@ -33,15 +33,15 @@
<view class="container-content">
<home-content class='home-content-class' headerItem='{{content}}' wx:if="{{bottomBtn==='front'}}" id="home-content-id"></home-content>
<blog class='home-content-class' id="blog-id" wx:if="{{bottomBtn==='blog'}}" bind:updateArticleMenu="updateArticleMenu"></blog>
<future class='home-content-class' wx:if="{{bottomBtn==='target'}}"></future>
<future class='home-content-class' wx:if="{{bottomBtn==='target'}}" bind:updateBottomNavigation="updateBottomNavigation"></future>
<life class='home-content-class' wx:if="{{bottomBtn==='life'}}" bindUserinfo="{{userInfo}}"></life>
</view>
<view class="container-footer">
<view class="container-footer" wx:if="{{isShowBottom}}">
<view class="container-footer-btn-menu">
<view class="default-btn active {{bottomBtn==='front'? 'btn-actived':''}}" bindtap="clickBottomBtn" data-label='front'>主页</view>
<view class="default-btn active {{bottomBtn==='blog'? 'btn-actived':''}}" bindtap="clickBottomBtn" data-label='blog'>博客</view>
<view class="default-btn active {{bottomBtn==='target'? 'btn-actived':''}}" bindtap="clickBottomBtn" data-label='target'>api管理</view>
<view class="default-btn active {{bottomBtn==='life'? 'btn-actived':''}}" bindtap="clickBottomBtn" data-label='life'>关于</view>
<view class="default-btn active {{bottomBtn==='front'? 'btn-actived':''}}" bindtap="clickBottomBtn" data-label='front'>{{bottomStyleConfig.homePageText}}</view>
<view class="default-btn active {{bottomBtn==='blog'? 'btn-actived':''}}" bindtap="clickBottomBtn" data-label='blog'>{{bottomStyleConfig.blogText}}</view>
<view class="default-btn active {{bottomBtn==='target'? 'btn-actived':''}}" bindtap="clickBottomBtn" data-label='target'>{{bottomStyleConfig.apiText}}</view>
<view class="default-btn active {{bottomBtn==='life'? 'btn-actived':''}}" bindtap="clickBottomBtn" data-label='life'>{{bottomStyleConfig.aboutText}}</view>
</view>
</view>
</view>
\ No newline at end of file
......@@ -24,16 +24,16 @@ Component({
article: {'key':12},
baseUrl:'https://yongma16.xyz/api/',
path:'article/blog/',
// 35, 34, 33, 32
currentArticleId:32,
},
observers:{
mode:function(val){
console.log('val',val)
}
},
lifetimes: {
// 生命周期函数,可以为函数,或一个在 methods 段中定义的方法名
attached: function () {
const id=app.homePageArticleId
const id=app.wxProgramConfig.homePageConfig.headBackground[0].articleId
this.getRemoteArticle(id)
},
moved: function () {},
......
// index.js
// const app = getApp()
// const { envList } = require('../../envList.js');
const app = getApp()
Page({
data: {
detailInfo: '关于:前端程序员的生活博客',
detailInfo: '关于:code笔记',
title: "yma16博客",
userImageUrl: "https://yongma16.xyz/staticFile/common/img/logo.png",
userImageUrl: "https://yongma16.xyz/staticFile/common/img/aiTop.jpg",
loginTitle: "点击授权",
userName: '',
joinTitle: '进入',
nextPage: "/pages/home/home",
userPrefix: '昵称:',
userName: '月牙天冲',
designPlaceholder: '自定义名称',
userInfo: {},
hasUserInfo: false,
isloading: true,
isOldVersion: false
},
getUserInfoBtn: function (info) {
fgetUserProfile
wx.showLoading({
title: '授权中',
});
......@@ -24,13 +27,49 @@ Page({
this.setData({
userImageUrl: rowData.avatarUrl,
userName: rowData.nickName,
userInfo:rowData
userInfo: rowData
})
wx.setStorageSync('currentUserInfo',rowData)
wx.setStorageSync('currentUserInfo', rowData)
console.log('rowData', rowData)
}
wx.hideLoading();
},
bindKeyInput(e) {
const { value } = e.detail
console.log('val', value)
this.setData({
userName: value
})
},
// 头像选择
onChooseAvatar(e) {
console.log('e', e)
const { avatarUrl } = e.detail
this.setData({
userImageUrl: avatarUrl,
})
},
joinProfile(e) {
const userInfo = {
nickName: this.data.userName,
avatarUrl: this.data.userImageUrl
}
if(!this.data.userName){
wx.showModal({
cancelColor: 'cancelColor',
title: '昵称不能为空!'
})
return
}
console.log('userInfo', userInfo)
wx.setStorageSync('currentUserInfo', userInfo)
this.setData({
userInfo: userInfo,
hasUserInfo: true
})
// 跳转到home
this.jumpTohome()
},
getUserProfile(e) {
// 推荐使用 wx.getUserProfile 获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
......@@ -38,8 +77,7 @@ Page({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log('信息', res)
console.log('信息', res.userInfo)
wx.setStorageSync('currentUserInfo',res.userInfo)
wx.setStorageSync('currentUserInfo', res.userInfo)
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
......@@ -53,15 +91,41 @@ Page({
jumpTohome: function () {
const thisBack = this
wx.navigateTo({
url: '/pages/home/home',
url: thisBack.data.nextPage,
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('setCurrentUserInfo', thisBack.data.userInfo)
res.eventChannel.emit('setHomePageData', {
userInfo: thisBack.data.userInfo
})
}
})
},
onLoad: function (options) {
this.jumpTohome()
console.log('option', options)
const authorPageConfig = app.wxProgramConfig.authorPageConfig
this.setData({
detailInfo: authorPageConfig.detailInfo,
title: authorPageConfig.title,
userImageUrl: authorPageConfig.userImageUrl,
loginTitle: authorPageConfig.loginTitle,
nextPage: authorPageConfig.nextPage,
userPrefix: authorPageConfig.userPrefix,
userName: authorPageConfig.userName,
designPlaceholder: authorPageConfig.designPlaceholder,
isOldVersion: authorPageConfig.isOldVersion,
joinTitle: authorPageConfig.joinTitle
})
// this.jumpTohome()
// 页面创建时执行
},
onShow: function () {
......@@ -90,22 +154,5 @@ Page({
},
onResize: function () {
// 页面尺寸变化时执行
},
userLogin: function () {
wx.login({
success(res) {
if (res.code) {
//发起网络请求
wx.request({
url: 'https://example.com/onLogin',
data: {
code: res.code
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
}
});
<view class="container">
<view class="title">{{title}}</view>
<view class="user-image-box">
<view class="user-nick-name">{{userName}}</view>
<view wx:if="{{isOldVersion}}">
<image class="user-image" src="{{userImageUrl}}"></image>
<view class="user-nick-name">{{userName}}</view>
</view>
<view wx:else>
<button class="avatar-wrapper" style="background: transparent;" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
<image class="avatar" class="user-image" src="{{userImageUrl}}"></image>
</button>
<view style="display: flex;width:100%">
<view style="width: 30%;text-align: right;">
{{userPrefix}}
</view>
<view style="width: 50%;text-align: center;">
<input type="nickname" class="weui-input" value="{{userName}}" bindinput="bindKeyInput"
placeholder-style="color: #07c160"
style="width: 100%;border-bottom: 1px solid #ffffff;" placeholder="{{designPlaceholder}}" />
</view>
</view>
</view>
</view>
<view class="user-info">
</view>
<view class="login-container">
<button type="primary" plain="true" bindtap="getUserProfile" class="user-login" bindgetuserinfo="getUserInfoBtn">{{loginTitle}}</button></view>
<button type="primary" plain="true" bindtap="getUserProfile" class="user-login" bindgetuserinfo="getUserInfoBtn" wx:if="{{isOldVersion}}">{{loginTitle}}</button>
<button type="primary" plain="true" bindtap="joinProfile" class="user-login" wx:else>{{joinTitle}}</button>
</view>
</view>
<view class="loading-container">
<view class="loading" wx:if="isloading">
<view class="loader-child"/>
<view class="loader-child"/>
<view class="loader-child"/>
</view>
<view class="loading" wx:if="isloading">
<view class="loader-child" />
<view class="loader-child" />
<view class="loader-child" />
</view>
</view>
<view class="detail-info">{{detailInfo}}</view>
\ No newline at end of file
......@@ -15,7 +15,9 @@ page {
.login-container{
margin-top:50px !important;
position: absolute;
top:50%;
transform: translateY(50%);
}
......@@ -49,7 +51,7 @@ page {
.title {
font-family: PingFang SC;
font-weight: 500;
font-size: 44rpx;
font-size: 22px;
margin-bottom: 40rpx;
}
......
......@@ -59,7 +59,7 @@ Component({
methods: {
initArticle() {
const articleId=app.lifePageArricleId
const articleId=app.wxProgramConfig.aboutPageConfig.articleId
this.getRemoteArticle(articleId)
},
......
{
"miniprogramRoot": "miniprogram/",
"cloudfunctionRoot": "cloudfunctions/",
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": true,
"es6": true,
......@@ -39,29 +41,37 @@
"showES6CompileOption": false,
"useCompilerPlugins": false
},
"compileType": "miniprogram",
"libVersion": "2.27.0",
"appid": "wx373f33f993c688d1",
"projectname": "yma16_program",
"libVersion": "2.27.0",
"miniprogramRoot": "miniprogram/",
"cloudfunctionRoot": "cloudfunctions/",
"cloudfunctionTemplateRoot": "cloudfunctionTemplate",
"condition": {
"search": {
"list": []
"watchOptions": {
"ignore": []
},
"conversation": {
"list": []
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"condition": {
"plugin": {
"list": []
},
"game": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": [
{
"id": -1,
"name": "db guide",
"pathName": "pages/databaseGuide/databaseGuide"
"name": "pages/getOpenId/index",
"pathName": "pages/getOpenId/index",
"query": "",
"scene": null
}
]
}
......
......@@ -12,52 +12,11 @@
},
"miniprogram": {
"list": [
{
"id": -1,
"name": "db guide",
"pathName": "pages/databaseGuide/databaseGuide",
"query": ""
},
{
"name": "pages/getOpenId/index",
"pathName": "pages/getOpenId/index",
"query": "",
"scene": null
},
{
"name": "pages/deployService/index",
"pathName": "pages/deployService/index",
"query": "",
"scene": null
},
{
"name": "pages/selectRecord/index",
"pathName": "pages/selectRecord/index",
"query": "",
"scene": null
},
{
"name": "pages/sumRecordResult/index",
"pathName": "pages/sumRecordResult/index",
"query": "",
"scene": null
},
{
"name": "pages/updateRecord/index",
"pathName": "pages/updateRecord/index",
"query": "",
"scene": null
},
{
"name": "pages/updateRecordResult/index",
"pathName": "pages/updateRecordResult/index",
"query": "",
"scene": null
},
{
"name": "pages/updateRecordSuccess/index",
"pathName": "pages/updateRecordSuccess/index",
"scene": null
}
]
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册