Commit 84cac4a349827d07640cf29fa72d2caef6a87b0d

Authored by pengye
1 parent cfaea1f9

分享卡片canvas文件

  1 +/* eslint-disable */
  2 +// 四则运算
  3 +
  4 +!(function () {
  5 + var calculate = function (s) {
  6 + s = s.trim();
  7 + const stack = new Array();
  8 + let preSign = '+';
  9 + let numStr = '';
  10 + const n = s.length;
  11 + for (let i = 0; i < n; ++i) {
  12 + if (s[i] === '.' || (!isNaN(Number(s[i])) && s[i] !== ' ')) {
  13 + numStr += s[i];
  14 + } else if (s[i] === '(') {
  15 + let isClose = 1;
  16 + let j = i;
  17 + while (isClose > 0) {
  18 + j += 1;
  19 + if (s[j] === '(') isClose += 1;
  20 + if (s[j] === ')') isClose -= 1;
  21 + }
  22 + numStr = `${calculate(s.slice(i + 1, j))}`;
  23 + i = j;
  24 + }
  25 + if ((isNaN(Number(s[i])) && s[i] !== '.') || i === n - 1) {
  26 + let num = parseFloat(numStr);
  27 + switch (preSign) {
  28 + case '+':
  29 + stack.push(num);
  30 + break;
  31 + case '-':
  32 + stack.push(-num);
  33 + break;
  34 + case '*':
  35 + stack.push(stack.pop() * num);
  36 + break;
  37 + case '/':
  38 + stack.push(stack.pop() / num);
  39 + break;
  40 + default:
  41 + break;
  42 + }
  43 + preSign = s[i];
  44 + numStr = '';
  45 + }
  46 + }
  47 + let ans = 0;
  48 + while (stack.length) {
  49 + ans += stack.pop();
  50 + }
  51 + return ans;
  52 + };
  53 + module.exports = calculate;
  54 +})();
  1 +String.prototype.substr = function (start, length) {
  2 + if (start === undefined) {
  3 + return this.toString()
  4 + }
  5 + if (typeof start !== 'number' || (typeof length !== 'number' && length !== undefined)) {
  6 + return ''
  7 + }
  8 + const strArr = [...this]
  9 + const _length = strArr.length
  10 + if (_length + start < 0) {
  11 + start = 0
  12 + }
  13 + if (length === undefined || (start < 0 && start + length > 0)) {
  14 + return strArr.slice(start).join('')
  15 + } else {
  16 + return strArr.slice(start, start + length).join('')
  17 + }
  18 +}
  19 +
  20 +
  21 +String.prototype.substring = function (start, end) {
  22 + if (start === undefined) {
  23 + return this.toString()
  24 + }
  25 + if (typeof start !== 'number' || (typeof end !== 'number' && end !== undefined)) {
  26 + return ''
  27 + }
  28 + if (!(start > 0)) {
  29 + start = 0
  30 + }
  31 + if (!(end > 0) && end !== undefined) {
  32 + end = 0
  33 + }
  34 + const strArr = [...this]
  35 + const _length = strArr.length
  36 + if (start > _length) {
  37 + start = _length
  38 + }
  39 + if (end > _length) {
  40 + end = _length
  41 + }
  42 + if (end < start) {
  43 + [start, end] = [end, start]
  44 + }
  45 + return strArr.slice(start, end).join('')
  46 +}
1 <view style='position: relative;{{customStyle}};{{painterStyle}}'> 1 <view style='position: relative;{{customStyle}};{{painterStyle}}'>
2 <block wx:if="{{!use2D}}"> 2 <block wx:if="{{!use2D}}">
3 - <canvas canvas-id="photo" style="{{photoStyle}};position: absolute; left: -9999px; top: -9999rpx;" />  
4 - <canvas canvas-id="bottom" style="{{painterStyle}};position: absolute;" />  
5 - <canvas canvas-id="k-canvas" style="{{painterStyle}};position: absolute;" />  
6 - <canvas canvas-id="top" style="{{painterStyle}};position: absolute;" />  
7 - <canvas  
8 - canvas-id="front"  
9 - style="{{painterStyle}};position: absolute;"  
10 - bindtouchstart="onTouchStart"  
11 - bindtouchmove="onTouchMove"  
12 - bindtouchend="onTouchEnd"  
13 - bindtouchcancel="onTouchCancel"  
14 - disable-scroll="{{true}}" /> 3 + <canvas canvas-id="photo" style="position: absolute; left: -9999px; top: -9999rpx;{{photoStyle}}" />
  4 + <canvas canvas-id="bottom" style="position: absolute;{{painterStyle}}" />
  5 + <canvas canvas-id="k-canvas" style="position: absolute;{{painterStyle}}" />
  6 + <canvas canvas-id="top" style="position: absolute;{{painterStyle}}" />
  7 + <canvas canvas-id="front" style="position: absolute;{{painterStyle}}" bindtouchstart="onTouchStart" bindtouchmove="onTouchMove" bindtouchend="onTouchEnd" bindtouchcancel="onTouchCancel" disable-scroll="{{true}}" />
15 </block> 8 </block>
16 <block wx:if="{{use2D}}"> 9 <block wx:if="{{use2D}}">
17 - <canvas type="2d" id="photo" style="{{photoStyle}};" /> 10 + <canvas type="2d" id="photo" style="{{photoStyle}}" />
18 <!-- <canvas type="2d" id="bottom" style="{{painterStyle}};position: absolute;" /> 11 <!-- <canvas type="2d" id="bottom" style="{{painterStyle}};position: absolute;" />
19 <canvas type="2d" id="k-canvas" style="{{painterStyle}};position: absolute;" /> 12 <canvas type="2d" id="k-canvas" style="{{painterStyle}};position: absolute;" />
20 <canvas type="2d" id="top" style="{{painterStyle}};position: absolute;" /> 13 <canvas type="2d" id="top" style="{{painterStyle}};position: absolute;" />
@@ -28,4 +21,4 @@ @@ -28,4 +21,4 @@
28 bindtouchcancel="onTouchCancel" 21 bindtouchcancel="onTouchCancel"
29 disable-scroll="{{true}}" /> --> 22 disable-scroll="{{true}}" /> -->
30 </block> 23 </block>
31 -</view> 24 +</view>
  1 +// canvas.js
  2 +module.exports = data => {
  3 + return ({
  4 + "width": "210px",
  5 + "height": "168px",
  6 + "views": [{
  7 + "type": "image",
  8 + "url": data.imgUrl,
  9 + "css": {
  10 + "width": "210px",
  11 + "height": "168px",
  12 + "top": "0px",
  13 + "left": "0px",
  14 + "mode": "aspectFill"
  15 + }
  16 + },
  17 + {
  18 + "type": "image",
  19 + "url": 'https://nosqn.colorcun.com/rectangleBj.png',
  20 + "css": {
  21 + "width": "210px",
  22 + "height": "168px",
  23 + "top": "0px",
  24 + "left": "0px",
  25 + "mode": "aspectFill"
  26 + }
  27 + },
  28 + {
  29 + "type": "text",
  30 + "text": data.sellerName,
  31 + "css": {
  32 + "color": "#fff",
  33 + "width": "190px",
  34 + "top": "10px",
  35 + "left": "10px",
  36 + "right": "10px",
  37 + "borderColor": "#000000",
  38 + "fontSize": "12px",
  39 + "fontWeight": "normal",
  40 + "maxLines": "2",
  41 + "textStyle": "fill",
  42 + "textDecoration": "none",
  43 + "fontFamily": "PingFang SC",
  44 + "textAlign": "center",
  45 + }
  46 + },
  47 + {
  48 + "type": "text",
  49 + "text": data.date,
  50 + "css": {
  51 + "color": "#fff",
  52 + "width": "210px",
  53 + "height": "168px",
  54 + "top": "70px",
  55 + "borderColor": "#000000",
  56 + "fontSize": "20px",
  57 + "fontWeight": "bold",
  58 + "maxLines": "3",
  59 + "textStyle": "fill",
  60 + "textDecoration": "none",
  61 + "fontFamily": "PingFang SC",
  62 + "textAlign": "center",
  63 + }
  64 + },
  65 + {
  66 + "type": "text",
  67 + "text": data.time,
  68 + "css": {
  69 + "color": "#fff",
  70 + "width": "210px",
  71 + "height": "168px",
  72 + "top": "100px",
  73 + "borderColor": "#000000",
  74 + "fontSize": "18px",
  75 + "fontWeight": "bold",
  76 + "maxLines": "3",
  77 + "textStyle": "fill",
  78 + "textDecoration": "none",
  79 + "fontFamily": "PingFang SC",
  80 + "textAlign": "center",
  81 + }
  82 + },
  83 + ]
  84 + });
  85 +}