electricity_bill_calc_wx/childPackage/pages/agreements/index.js

104 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/agreements/index.js
import towxml from "towxml"
import { alertInfo } from "../../../utils/index";
Page({
/**
* 页面的初始数据
*/
data: {
url: ""
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
const { url } = options;
this.getText(url, this.setText)
},
getText: (url, callback) => {
wx.request({
url: url,
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: (res) => {
if (typeof callback === 'function') {
callback(res);
};
},
fail: (err) => {
alertInfo(err)
}
});
},
async setText(res) {
let obj = towxml(res.data,'markdown',{
       theme:'light', //主题 dark 黑色light白色不填默认是light
//        base:"www.xxx.com",
events:{      //为元素绑定的事件方法
tap:e => {
console.log('tap',e);
},
change:e => {
console.log('todo',e);
}
}
});
     //更新解析数据
this.setData({
text:obj,
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})