1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- // miniprogram/pages/detail/detail.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- detail: {}
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: async function (options) {
- wx.setNavigationBarTitle({
- title: options.title || "详情"
- })
- const db = wx.cloud.database();
- const _ = db.command;
- const _this = this;
- let list = await db.collection('data_news').where({
- _id: _.eq(options.id)
- }).get();
- if (!list.data.length) return wx.showToast({
- title: '数据走丢了',
- icon: "error"
- })
- let D = list.data[0] || {};
- console.log(D.content.match(/style=\"([a-z|A-Z|-|:|;|0-9]*)\"/g))
- D.content = D.content.replace(/<p/gi, '<p style="text-indent: 2em"').replace(/style=\"([a-z|A-Z|-|:|;|0-9|\.]*)\"/g, "").replace(/width=\"([a-z|A-Z|-|:|;|0-9|\.]*)\"/g, "").replace(/height=\"([a-z|A-Z|-|:|;|0-9|\.]*)\"/g, "").replace(/<img/g, "<img style='width: 100%'")
- if (D.creat_time) D.creat_time = this.format(D.creat_time);
- _this.setData({
- detail: D
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- format: function (res) {
- if (!res) return "";
- let num = (res || 0) - 0;
- let T = new Date(num);
- let year = T.getFullYear();
- let month = T.getMonth() + 1;
- let day = T.getDate();
- let hour = T.getHours();
- let min = T.getMinutes() + 1;
- let sec = T.getSeconds();
- return year + "-" + (month > 9 ? month : "0" + month) + "-" + day + " " + (hour > 9 ? hour : '0' + hour) + ":" + (min > 9 ? min : '0' + min) + ":" + (sec > 9 ? sec : '0' + sec);
- },
- })
|