|
@@ -1,18 +1,20 @@
|
|
|
// pages/downZS/index.js
|
|
|
+import {
|
|
|
+ ajax,
|
|
|
+} from "../../utils/util";
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
- ls_url: "",
|
|
|
- selectIndex: 0,
|
|
|
- users: []
|
|
|
+ ls_url: [],
|
|
|
+ selectIndex: 0
|
|
|
},
|
|
|
systemInfo: wx.getSystemInfoSync(),
|
|
|
|
|
|
-
|
|
|
- goBack(){
|
|
|
+
|
|
|
+ goBack() {
|
|
|
wx.navigateBack();
|
|
|
},
|
|
|
|
|
@@ -20,13 +22,14 @@ Page({
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad(options) {
|
|
|
- // 获取远程图片
|
|
|
wx.showLoading({
|
|
|
title: '加载中',
|
|
|
mask: true
|
|
|
})
|
|
|
+
|
|
|
+ // 获取远程图片
|
|
|
wx.getImageInfo({
|
|
|
- src: "https://cxzx.smcic.net/topic/tool/img/%E5%B0%91%E5%84%BF%E4%B9%A6%E7%94%BB%E5%A4%A7%E8%B5%9B/6.jpg",
|
|
|
+ src: "https://cxzx.smcic.net/topic/tool/img/%E5%B0%91%E5%84%BF%E4%B9%A6%E7%94%BB%E5%A4%A7%E8%B5%9B/6.jpg?" + Date.now(),
|
|
|
}).then((res) => {
|
|
|
wx.hideLoading();
|
|
|
const {
|
|
@@ -34,7 +37,6 @@ Page({
|
|
|
height,
|
|
|
path
|
|
|
} = res;
|
|
|
- const users = JSON.parse(JSON.stringify(this.data.users));
|
|
|
const canvas = wx.createOffscreenCanvas({
|
|
|
type: '2d',
|
|
|
width,
|
|
@@ -43,34 +45,47 @@ Page({
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
const img = canvas.createImage();
|
|
|
img.onload = () => {
|
|
|
- for (let i = 0; i < users.length; i++) {
|
|
|
- const v = users[i];
|
|
|
- ctx.drawImage(img, 0, 0, width, height);
|
|
|
- ctx.fillStyle = "#000000";
|
|
|
- ctx.font = (width / 20) + 'px 微软雅黑';
|
|
|
- ctx.fillText(v.name, width * 0.18, height * 0.4);
|
|
|
- wx.canvasToTempFilePath({
|
|
|
- x: 0,
|
|
|
- y: 0,
|
|
|
- width,
|
|
|
- height,
|
|
|
- destWidth: width,
|
|
|
- destHeight: height,
|
|
|
- canvas,
|
|
|
- fileType: 'jpg',
|
|
|
- success: res => {
|
|
|
- v.url = res.tempFilePath
|
|
|
- if (i === users.length - 1) {
|
|
|
- this.setData({
|
|
|
- ls_url: users,
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
- complete: () => {
|
|
|
- wx.hideLoading();
|
|
|
- }
|
|
|
+ ajax({
|
|
|
+ urlType: "apiurl",
|
|
|
+ api: "/article/list",
|
|
|
+ }).then(res => {
|
|
|
+ if (res.code !== 0) return wx.showToast({
|
|
|
+ title: res.message || '请求失败',
|
|
|
+ icon: 'none'
|
|
|
})
|
|
|
- }
|
|
|
+ const li = res.data || [];
|
|
|
+ console.log(li)
|
|
|
+ for (let i = 0; i < li.length; i++) {
|
|
|
+ const v = li[i];
|
|
|
+ ctx.drawImage(img, 0, 0, width, height);
|
|
|
+ ctx.fillStyle = "#000000";
|
|
|
+ ctx.font = (width / 20) + 'px 微软雅黑';
|
|
|
+ ctx.fillText(v.name, width * 0.18, height * 0.4);
|
|
|
+ wx.canvasToTempFilePath({
|
|
|
+ x: 0,
|
|
|
+ y: 0,
|
|
|
+ width,
|
|
|
+ height,
|
|
|
+ destWidth: width,
|
|
|
+ destHeight: height,
|
|
|
+ canvas,
|
|
|
+ fileType: 'jpg',
|
|
|
+ success: res => {
|
|
|
+ v.url = res.tempFilePath
|
|
|
+ if (i === li.length - 1) {
|
|
|
+ this.setData({
|
|
|
+ ls_url: li,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ complete: () => {
|
|
|
+ wx.hideLoading();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }).catch(err => {
|
|
|
+ wx.hideLoading();
|
|
|
+ })
|
|
|
}
|
|
|
img.onerror = () => wx.hideLoading();
|
|
|
img.src = path // 要加载的图片 url
|