// pages/future/future.js const app = getApp(); const baseUrl = app.remoteConfig.baseUrl; Component({ /** * 继承父级样式 */ options: { addGlobalClass: true, }, /** *组件的初始数据 */ data: { content: '子组件的content', btnType:'map', homeHeaderItem: '', isLoading: false, article: { 'key': 12 }, searchOpenAiText:'', responseText:'', // questions,answer,index chatObjConfig:{ option:[{ question:'', answer:'', isEdit:true }], currentIndex:0 } }, observers: { }, lifetimes: { // 生命周期函数,可以为函数,或一个在 methods 段中定义的方法名 attached: function () { if(wx.getStorageSync('openAiOptions')){ this.setData( { chatObjConfig:wx.getStorageSync('openAiOptions') } ) } }, moved: function () { }, detached: function () { wx.setStorageSync('openAiOptions', this.data.chatObjConfig) }, }, // 生命周期函数,可以为函数,或一个在 methods 段中定义的方法名 // attached: function () { }, // 此处 attached 的声明会被 lifetimes 字段中的声明覆盖 // ready: function() { }, pageLifetimes: { // 组件所在页面的生命周期函数 show: function () { console.log('pageLifetimes') }, hide: function () { }, resize: function () { }, }, methods: { 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 return true } return false }) this.setData({ searchOpenAiText:e.detail.value, chatObjConfig:{ option:option, currentIndex:columnIndex } }) }, search(e){ console.log(this.data.searchOpenAiText) if(!this.data.searchOpenAiText){ wx.showModal({ cancelColor: 'cancelColor', title:'请输入!' }) } wx.showLoading({ title: '加载中', }) this.setData({ isLoading: true }) console.log(e) const path = '/common-api/searchOpenAiText/' const headers = { 'Content-Type': 'application/json;charset=UTF-8' } const params={ "text":this.data.searchOpenAiText } const thisBack=this return new Promise((resolve, reject) => { wx.request({ url: baseUrl + path, headers: headers, 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) option.some((item,index)=>{ if(currentIndex===index){ item.answer=choices?choices.map(choicesItem=>{return choicesItem.text}).join('\n'):'。。。未知' item.isEdit=false return true } return false }) const chatObjConfig={ option:option, currentIndex:currentIndex+1 } option.push({ question:'', answer:'', isEdit:true }) thisBack.setData( { isLoading: false, chatObjConfig:chatObjConfig } ) setTimeout(function () { wx.hideLoading() }, 2000) resolve(res) }, fail: error => { thisBack.setData({ isLoading: false }) setTimeout(function () { wx.hideLoading() }, 2000) reject(error) } }); }) }, clickHeadBtn(e){ console.log(e) const {btnType}=e.currentTarget.dataset this.setData( {btnType:btnType} ) }, async initData() { await this.getGeoJson() await this.getOutBreakData() this.setData({ isLoading: false }) }, getGeoJson() { if(app.globalData.geoJson){ return new Promise(resolve=>{ resolve() }) } const path = '/common-api/mapApp/getGeoJson/' const headers = { 'Content-Type': 'application/json;charset=UTF-8' } return new Promise((resolve, reject) => { wx.request({ url: baseUrl + path, headers: headers, method: 'GET', success: (res) => { app.globalData.geoJson = res.data.data const geoAdcodeMap = [] app.globalData.geoJson.features.map(item => { const { properties } = item geoAdcodeMap.push({ name: properties.name, adcode: properties.adcode }) }) app.globalData.geoAdcodeMap = [...geoAdcodeMap] resolve(res.data.data) }, fail: error => { reject(error) } }); }) }, getOutBreakData() { if(app.globalData.hotData){ return new Promise(resolve=>{ resolve() }) } const path = '/common-api/mapApp/outBreak/' const headers = { 'Content-Type': 'application/json;charset=UTF-8' } return new Promise((resolve, reject) => { wx.request({ url: baseUrl + path, headers: headers, method: 'GET', success: (res) => { app.globalData.hotData = res.data.data /** * @type {string} 贵州省 adcode */ const targetAdcode = "520000" const targetItem = app.globalData.hotData.areaTree[0].children.find(item => { return item.adcode === targetAdcode }) app.globalData.hotData.targetItem={...targetItem} resolve(res.data.data) }, fail: error => { reject(error) } }); }) }, onMyButtonTap: function () { this.setData({ // 更新属性和数据的方法与更新页面数据的方法类似 }) }, // 内部方法建议以下划线开头 _myPrivateMethod: function () { // 这里将 data.A[0].B 设为 'myPrivateData' // this.setData({ // 'A[0].B': 'myPrivateData' // }) }, _propertyChange: function (newVal, oldVal) { } } })