在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
作者:gou-tian 来自:github
<view class="show-warp">
<block wx:for="{{discuss}}" wx:key="index">
<template is="discuss" data="{{item}}"></template>
<template is="discuss-reply" data="{{item}}"></template>
<template is="discuss-more" data="{{item}}"></template>
</block>
</view>
Page({ data: { discuss: [], petAge: 0, reply: false, height: 20 }, onLoad: function(){ util.dataList.call(this, { cb: util.petAge }); } }); /* * 部分公共逻辑页代码 */ function list(option) { var opt = { url: option.url || 'https://api.zg5v.com/index.php/index/show/showindex', data: option.data || { uid: 148, num: option.pageNum || 0 }, update: option.update || false, cb: option.cb || false, func: option.func || false }; // 数据列表 var showList = []; var objDa = []; this.data.replyListArr = []; // 保存/修改 this指向 var self = this; ajax({ url: opt.url, data: opt.data, cb: function(res) { showList = res.data.data; // 统一格式 if (!Array.isArray(showList) && typeof showList === 'object') { // 计算评论发布时间 showList.pl.forEach(function(e, i) { e.cp_chongbirth = e.cp_addtime * 1000; e.replyTime = opt.cb(e.cp_chongbirth, true); }, showList.pl); objDa.push(showList); } else { objDa = showList; } // 更新评论列表 if (opt.update) { let da = res.data.data.pl, plDa = self.data.discuss, i = 0, j = 0, len = da.length, jLen = plDa.length; for (; j < jLen; j++) { for (; i < len; i++) { if (plDa[j].pl.length > 0) { plDa[j].pl.push(da[i]); } } } objDa = plDa; opt.update = !opt.update; } if (res.data.status === 1) { for (var i = 0, len = objDa.length; i < len; i++) { if (opt.cb && typeof opt.cb === 'function') { // 计算宠物年龄 objDa[i].petAge = opt.cb(objDa[i].cp_chongbir || objDa[i].cp_chongbirth); } } self.setData({ discuss: objDa }); } else if (res.data.status === 2 || res.data.status === 0) { self.onLoad(); } objDa = []; } }); }
上传文件编码问题(*)
header: {“chartset”:”utf-8”} 或是
header: {"content-type":'application/x-www-form-urlencoded'}
wx.uploadFile({ url: 'Upload image server path (Must be secure https)', // 待上传的图片,由 chooseImage获得 filePath: tempFilePaths[0], name: 'file', // HTTP 请求中其他额外的 form data formData: { // city: '太原', city: encodeURI('太原'), // name: 'taiyan', name: encodeURI('taiyan') // 名称 }, success: function(res) { console.log("success", res); }, fail: function(res) { console.log("fail", res); } });
转自:转载地址 |
请发表评论