// pages/future/future.js const app = getApp(); const baseUrl = app.remoteConfig.baseUrl; Component({ /** * 继承父级样式 */ options: { addGlobalClass: true, }, /** *组件的初始数据 */ data: { content: '子组件的content', btnType:'map', homeHeaderItem: '', isLoading: true, article: { 'key': 12 } }, observers: { }, lifetimes: { // 生命周期函数,可以为函数,或一个在 methods 段中定义的方法名 attached: function () { this.initData() }, moved: function () { }, detached: function () { }, }, // 生命周期函数,可以为函数,或一个在 methods 段中定义的方法名 // attached: function () { }, // 此处 attached 的声明会被 lifetimes 字段中的声明覆盖 // ready: function() { }, pageLifetimes: { // 组件所在页面的生命周期函数 show: function () { console.log('pageLifetimes') }, hide: function () { }, resize: function () { }, }, methods: { 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) { } } })