Commit 84cac4a349827d07640cf29fa72d2caef6a87b0d

Authored by pengye
1 parent cfaea1f9

分享卡片canvas文件

/* eslint-disable */
// 四则运算
!(function () {
var calculate = function (s) {
s = s.trim();
const stack = new Array();
let preSign = '+';
let numStr = '';
const n = s.length;
for (let i = 0; i < n; ++i) {
if (s[i] === '.' || (!isNaN(Number(s[i])) && s[i] !== ' ')) {
numStr += s[i];
} else if (s[i] === '(') {
let isClose = 1;
let j = i;
while (isClose > 0) {
j += 1;
if (s[j] === '(') isClose += 1;
if (s[j] === ')') isClose -= 1;
}
numStr = `${calculate(s.slice(i + 1, j))}`;
i = j;
}
if ((isNaN(Number(s[i])) && s[i] !== '.') || i === n - 1) {
let num = parseFloat(numStr);
switch (preSign) {
case '+':
stack.push(num);
break;
case '-':
stack.push(-num);
break;
case '*':
stack.push(stack.pop() * num);
break;
case '/':
stack.push(stack.pop() / num);
break;
default:
break;
}
preSign = s[i];
numStr = '';
}
}
let ans = 0;
while (stack.length) {
ans += stack.pop();
}
return ans;
};
module.exports = calculate;
})();
\ No newline at end of file
... ...
String.prototype.substr = function (start, length) {
if (start === undefined) {
return this.toString()
}
if (typeof start !== 'number' || (typeof length !== 'number' && length !== undefined)) {
return ''
}
const strArr = [...this]
const _length = strArr.length
if (_length + start < 0) {
start = 0
}
if (length === undefined || (start < 0 && start + length > 0)) {
return strArr.slice(start).join('')
} else {
return strArr.slice(start, start + length).join('')
}
}
String.prototype.substring = function (start, end) {
if (start === undefined) {
return this.toString()
}
if (typeof start !== 'number' || (typeof end !== 'number' && end !== undefined)) {
return ''
}
if (!(start > 0)) {
start = 0
}
if (!(end > 0) && end !== undefined) {
end = 0
}
const strArr = [...this]
const _length = strArr.length
if (start > _length) {
start = _length
}
if (end > _length) {
end = _length
}
if (end < start) {
[start, end] = [end, start]
}
return strArr.slice(start, end).join('')
}
\ No newline at end of file
... ...
<view style='position: relative;{{customStyle}};{{painterStyle}}'>
<block wx:if="{{!use2D}}">
<canvas canvas-id="photo" style="{{photoStyle}};position: absolute; left: -9999px; top: -9999rpx;" />
<canvas canvas-id="bottom" style="{{painterStyle}};position: absolute;" />
<canvas canvas-id="k-canvas" style="{{painterStyle}};position: absolute;" />
<canvas canvas-id="top" style="{{painterStyle}};position: absolute;" />
<canvas
canvas-id="front"
style="{{painterStyle}};position: absolute;"
bindtouchstart="onTouchStart"
bindtouchmove="onTouchMove"
bindtouchend="onTouchEnd"
bindtouchcancel="onTouchCancel"
disable-scroll="{{true}}" />
<canvas canvas-id="photo" style="position: absolute; left: -9999px; top: -9999rpx;{{photoStyle}}" />
<canvas canvas-id="bottom" style="position: absolute;{{painterStyle}}" />
<canvas canvas-id="k-canvas" style="position: absolute;{{painterStyle}}" />
<canvas canvas-id="top" style="position: absolute;{{painterStyle}}" />
<canvas canvas-id="front" style="position: absolute;{{painterStyle}}" bindtouchstart="onTouchStart" bindtouchmove="onTouchMove" bindtouchend="onTouchEnd" bindtouchcancel="onTouchCancel" disable-scroll="{{true}}" />
</block>
<block wx:if="{{use2D}}">
<canvas type="2d" id="photo" style="{{photoStyle}};" />
<canvas type="2d" id="photo" style="{{photoStyle}}" />
<!-- <canvas type="2d" id="bottom" style="{{painterStyle}};position: absolute;" />
<canvas type="2d" id="k-canvas" style="{{painterStyle}};position: absolute;" />
<canvas type="2d" id="top" style="{{painterStyle}};position: absolute;" />
... ... @@ -28,4 +21,4 @@
bindtouchcancel="onTouchCancel"
disable-scroll="{{true}}" /> -->
</block>
</view>
</view>
\ No newline at end of file
... ...
// canvas.js
module.exports = data => {
return ({
"width": "210px",
"height": "168px",
"views": [{
"type": "image",
"url": data.imgUrl,
"css": {
"width": "210px",
"height": "168px",
"top": "0px",
"left": "0px",
"mode": "aspectFill"
}
},
{
"type": "image",
"url": 'https://nosqn.colorcun.com/rectangleBj.png',
"css": {
"width": "210px",
"height": "168px",
"top": "0px",
"left": "0px",
"mode": "aspectFill"
}
},
{
"type": "text",
"text": data.sellerName,
"css": {
"color": "#fff",
"width": "190px",
"top": "10px",
"left": "10px",
"right": "10px",
"borderColor": "#000000",
"fontSize": "12px",
"fontWeight": "normal",
"maxLines": "2",
"textStyle": "fill",
"textDecoration": "none",
"fontFamily": "PingFang SC",
"textAlign": "center",
}
},
{
"type": "text",
"text": data.date,
"css": {
"color": "#fff",
"width": "210px",
"height": "168px",
"top": "70px",
"borderColor": "#000000",
"fontSize": "20px",
"fontWeight": "bold",
"maxLines": "3",
"textStyle": "fill",
"textDecoration": "none",
"fontFamily": "PingFang SC",
"textAlign": "center",
}
},
{
"type": "text",
"text": data.time,
"css": {
"color": "#fff",
"width": "210px",
"height": "168px",
"top": "100px",
"borderColor": "#000000",
"fontSize": "18px",
"fontWeight": "bold",
"maxLines": "3",
"textStyle": "fill",
"textDecoration": "none",
"fontFamily": "PingFang SC",
"textAlign": "center",
}
},
]
});
}
\ No newline at end of file
... ...