From e8353b1423ea5da0c5482574115e42ed33f53954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=93=E5=B9=B3=E8=89=BA?= <52643018@qq.com> Date: Mon, 6 Sep 2021 11:36:11 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=96=B0=E5=A2=9E]=20=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E4=BC=9A=E5=91=98=E7=A0=81=E9=A1=B5=E9=9D=A2UI=20[=E6=96=B0?= =?UTF-8?q?=E5=A2=9E]=20=E7=94=9F=E6=88=90=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E3=80=81=E6=9D=A1=E5=BD=A2=E7=A0=81=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/lf-code/helper.js | 54 ++++++++ components/lf-code/index.js | 2 + components/lf-code/lf-barcode.vue | 87 +++++++++++++ components/lf-code/lf-qrcode.vue | 84 +++++++++++++ pages.json | 7 ++ pages/user/member/code.vue | 199 ++++++++++++++++++++++++++++++ 6 files changed, 433 insertions(+) create mode 100644 components/lf-code/helper.js create mode 100644 components/lf-code/index.js create mode 100644 components/lf-code/lf-barcode.vue create mode 100644 components/lf-code/lf-qrcode.vue create mode 100644 pages/user/member/code.vue diff --git a/components/lf-code/helper.js b/components/lf-code/helper.js new file mode 100644 index 0000000..9d7ba6e --- /dev/null +++ b/components/lf-code/helper.js @@ -0,0 +1,54 @@ +// 判断arr是否为一个数组,返回一个bool值 +function isArray(arr) { + return Object.prototype.toString.call(arr) === '[object Array]'; +} +// 深度克隆 +function deepClone(obj) { + // 对常见的“非”值,直接返回原来值 + if ([null, undefined, NaN, false].includes(obj)) return obj; + if (typeof obj !== "object" && typeof obj !== 'function') { + //原始类型直接返回 + return obj; + } + var o = isArray(obj) ? [] : {}; + for (let i in obj) { + if (obj.hasOwnProperty(i)) { + o[i] = typeof obj[i] === "object" ? deepClone(obj[i]) : obj[i]; + } + } + return o; +} + +function getUUid(len = 32, firstU = true, radix = null) { + let chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''); + let uuid = []; + radix = radix || chars.length; + + if (len) { + // 如果指定uuid长度,只是取随机的字符,0|x为位运算,能去掉x的小数位,返回整数位 + for (let i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]; + } else { + let r; + // rfc4122标准要求返回的uuid中,某些位为固定的字符 + uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; + uuid[14] = '4'; + + for (let i = 0; i < 36; i++) { + if (!uuid[i]) { + r = 0 | Math.random() * 16; + uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]; + } + } + } + // 移除第一个字符,并用u替代,因为第一个字符为数值时,该guuid不能用作id或者class + if (firstU) { + uuid.shift(); + return 'u' + uuid.join(''); + } else { + return uuid.join(''); + } +} +export { + deepClone, + getUUid +}; diff --git a/components/lf-code/index.js b/components/lf-code/index.js new file mode 100644 index 0000000..ad38059 --- /dev/null +++ b/components/lf-code/index.js @@ -0,0 +1,2 @@ +let $jscomp=$jscomp||{};let regUtf=new RegExp("[\\u4E00-\\u9FFF]+","g");$jscomp.scope={};$jscomp.arrayIteratorImpl=function(k){let l=0;return function(){return l=0x0001)&&(c<=0x007F)){out+=code.charAt(i);}else if(c>0x07FF){out+=String.fromCharCode(0xE0|((c>>12)&0x0F));out+=String.fromCharCode(0x80|((c>>6)&0x3F));out+=String.fromCharCode(0x80|((c>>0)&0x3F));}else{out+=String.fromCharCode(0xC0|((c>>6)&0x1F));out+=String.fromCharCode(0x80|((c>>0)&0x3F));}}return out;},SaveImg:function(k){const width=uni.upx2px(Number(k.width));const height=uni.upx2px(Number(k.height));return new Promise(function(z,H){if(Object.prototype.toString.call(k.id)=='[object String]'){uni.canvasToTempFilePath({canvasId:k.id,width:width,height:height,destWidth:width,destHeight:height,fileType:k.type||'png',complete:function(B){z(B)}},k.ctx)}else if(Object.prototype.toString.call(k.id)=='[object Object]'){const ctx=k.id;ctx.toTempFilePath(0,0,width,height,width,height,k.type||'png',1,function(B){z(B)})}})},BarCode:function(k,callback){function l(e,C){return"undefined"==typeof C?32<=e?e-32:e+64:parseInt(String.fromCharCode(e)+String.fromCharCode(C))}function v(e,C){e=z(e);return e==CODESET.ANY||e==CODESET.AB||e==CODESET.A&&C==CODESET.A||e==CODESET.B&&C==CODESET.B?!0:!1}function z(e){return 48<=e&&57>=e?CODESET.ANY:32<=e&&95>=e?CODESET.AB:32>e?CODESET.A:CODESET.B}function H(e){for(var C=[],n=0;nD||57q+1?e[q+1]:-1,n));n==CODESET.C&&q++}e=d[0];for(q=1;qI;I+=2){var J=PATTERNS[M][I]*L,m=N-U,E=PATTERNS[M][I+1]*L;0{if(callback&&typeof callback==="function"&&typeof callback.nodeType!=="number"){callback({...res,id:k.id})}});},QRCode:function(k,callback){function l(b,a){if(b>a){var c=b;b=a;a=c}c=(a*a+a>>1)+b;C[c]=1}function v(b,a){var c;e[b+d*a]=1;for(c=-2;2>c;c++)e[b+c+d*(a-2)]=1,e[b-2+d*(a+c+1)]=1,e[b+2+d*(a+c)]=1,e[b+c+1+d*(a+2)]=1;for(c=0;2>c;c++)l(b-1,a+c),l(b+1,a-c),l(b-c,a-1),l(b+c,a+1)}function z(b){for(;255<=b;)b-=255,b=(b>>8)+(b&255);return b}function H(b,a,c,g){var h,f;for(h=0;ha){var c=b;b=a;a=c}c=(a+a*a>>1)+b;return C[c]}function L(b){var a,c,g;switch(b){case 0:for(a=0;a>1&1,b=0;bb||3*n[a-3]>=4*n[a]||3*n[a+3]>=4*n[a])&&(c+=40);return c}function O(b){var a,c,g;var h=b.length;q=0;do{q++;var f=4*(D-1)+16*(q-1);A=M[f++];u=M[f++];r=M[f++];p=M[f];f=r*(A+u)+u-3+(9>=q);if(h<=f)break}while(40>q);d=17+4*q;var t=r+(r+p)*(A+u)+u;for(h=0;hh;h++){b=f=0;1==h&&(f=d-7);2==h&&(b=d-7);e[b+3+d*(f+3)]=1;for(a=0;6>a;a++)e[b+a+d*f]=1,e[b+d*(f+a+1)]=1,e[b+6+d*(f+a)]=1,e[b+a+1+d*(f+6)]=1;for(a=1;5>a;a++)l(b+a,f+1),l(b+1,f+a+1),l(b+5,f+a),l(b+a+1,f+5);for(a=2;4>a;a++)e[b+a+d*(f+2)]=1,e[b+2+d*(f+a+1)]=1,e[b+4+d*(f+a)]=1,e[b+a+1+d*(f+4)]=1}if(1h-3;){v(a,b);if(ab;b++)l(7,b),l(d-8,b),l(7,b+d-7);for(a=0;8>a;a++)l(a,7),l(a+d-8,7),l(a,d-8);for(a=0;9>a;a++)l(a,8);for(a=0;8>a;a++)l(a+d-8,8),l(8,a);for(b=0;7>b;b++)l(8,b+d-7);for(a=0;aa;a++)for(b=0;3>b;b++,f--)1&(11>f-12:h>>f)?(e[5-a+d*(2-b+d-11)]=1,e[2-b+d-11+d*(5-a)]=1):(l(5-a,2-b+d-11),l(2-b+d-11,5-a));for(b=0;b=a-2&&(t=a-2,9>4;m[2]|=255&t<<4;m[1]=t>>4;m[0]=64|t>>12}else{m[c+1]=0;for(m[c+2]=0;c--;)h=m[c],m[c+2]|=255&h<<4,m[c+1]=h>>4;m[1]|=255&t<<4;m[0]=64|t>>4}for(c=t+3-(10>q);cg;g++,h<<=1){128&h&&(e[a+d*b]=1);do t?a--:(a++,f?0!=b?b--:(a-=2,f=!f,6==a&&(a--,b=9)):b!=d-1?b++:(a-=2,f=!f,6==a&&(a--,b-=8))),t=!t;while(B(a,b))}m=e.slice(0);h=0;b=3E4;for(f=0;8>f;f++){L(f);var y,Q=t=0;for(x=0;xQ&&(Q=-Q);a=Q;c=0;for(a=a+(a<<2)<<1;a>d*d;)a-=d*d,c++;t+=10*c;for(y=0;yf;f++,b>>=1)b&1&&(e[d-1-f+8*d]=1,6>f?e[8+d*f]=1:e[8+d*(f+1)]=1);for(f=0;7>f;f++,b>>=1)b&1&&(e[8+d*(d-7+f)]=1,f?e[6-f+8*d]=1:e[7+8*d]=1);return e}var T=[0,11,15,19,23,27,31,16,18,20,22,24,26,28,20,22,24,24,26,28,28,22,24,24,26,26,28,28,24,24,26,26,26,28,28,24,26,26,26,28,28],U=[3220,1468,2713,1235,3062,1890,2119,1549,2344,2936,1117,2583,1330,2470,1667,2249,2028,3780,481,4011,142,3098,831,3445,592,2517,1776,2234,1951,2827,1070,2660,1345,3177],P=[30660,29427,32170,30877,26159,25368,27713,26998,21522,20773,24188,23371,17913,16590,20375,19104,13663,12392,16177,14854,9396,8579,11994,11245,5769,5054,7399,6608,1890,597,3340,2107],M=[1,0,19,7,1,0,16,10,1,0,13,13,1,0,9,17,1,0,34,10,1,0,28,16,1,0,22,22,1,0,16,28,1,0,55,15,1,0,44,26,2,0,17,18,2,0,13,22,1,0,80,20,2,0,32,18,2,0,24,26,4,0,9,16,1,0,108,26,2,0,43,24,2,2,15,18,2,2,11,22,2,0,68,18,4,0,27,16,4,0,19,24,4,0,15,28,2,0,78,20,4,0,31,18,2,4,14,18,4,1,13,26,2,0,97,24,2,2,38,22,4,2,18,22,4,2,14,26,2,0,116,30,3,2,36,22,4,4,16,20,4,4,12,24,2,2,68,18,4,1,43,26,6,2,19,24,6,2,15,28,4,0,81,20,1,4,50,30,4,4,22,28,3,8,12,24,2,2,92,24,6,2,36,22,4,6,20,26,7,4,14,28,4,0,107,26,8,1,37,22,8,4,20,24,12,4,11,22,3,1,115,30,4,5,40,24,11,5,16,20,11,5,12,24,5,1,87,22,5,5,41,24,5,7,24,30,11,7,12,24,5,1,98,24,7,3,45,28,15,2,19,24,3,13,15,30,1,5,107,28,10,1,46,28,1,15,22,28,2,17,14,28,5,1,120,30,9,4,43,26,17,1,22,28,2,19,14,28,3,4,113,28,3,11,44,26,17,4,21,26,9,16,13,26,3,5,107,28,3,13,41,26,15,5,24,30,15,10,15,28,4,4,116,28,17,0,42,26,17,6,22,28,19,6,16,30,2,7,111,28,17,0,46,28,7,16,24,30,34,0,13,24,4,5,121,30,4,14,47,28,11,14,24,30,16,14,15,30,6,4,117,30,6,14,45,28,11,16,24,30,30,2,16,30,8,4,106,26,8,13,47,28,7,22,24,30,22,13,15,30,10,2,114,28,19,4,46,28,28,6,22,28,33,4,16,30,8,4,122,30,22,3,45,28,8,26,23,30,12,28,15,30,3,10,117,30,3,23,45,28,4,31,24,30,11,31,15,30,7,7,116,30,21,7,45,28,1,37,23,30,19,26,15,30,5,10,115,30,19,10,47,28,15,25,24,30,23,25,15,30,13,3,115,30,2,29,46,28,42,1,24,30,23,28,15,30,17,0,115,30,10,23,46,28,10,35,24,30,19,35,15,30,17,1,115,30,14,21,46,28,29,19,24,30,11,46,15,30,13,6,115,30,14,23,46,28,44,7,24,30,59,1,16,30,12,7,121,30,12,26,47,28,39,14,24,30,22,41,15,30,6,14,121,30,6,34,47,28,46,10,24,30,2,64,15,30,17,4,122,30,29,14,46,28,49,10,24,30,24,46,15,30,4,18,122,30,13,32,46,28,48,14,24,30,42,32,15,30,20,4,117,30,40,7,47,28,43,22,24,30,10,67,15,30,19,6,118,30,18,31,47,28,34,34,24,30,20,61,15,30],I=[255,0,1,25,2,50,26,198,3,223,51,238,27,104,199,75,4,100,224,14,52,141,239,129,28,193,105,248,200,8,76,113,5,138,101,47,225,36,15,33,53,147,142,218,240,18,130,69,29,181,194,125,106,39,249,185,201,154,9,120,77,228,114,166,6,191,139,98,102,221,48,253,226,152,37,179,16,145,34,136,54,208,148,206,143,150,219,189,241,210,19,92,131,56,70,64,30,66,182,163,195,72,126,110,107,58,40,84,250,133,186,61,202,94,155,159,10,21,121,43,78,212,229,172,115,243,167,87,7,112,192,247,140,128,99,13,103,74,222,237,49,197,254,24,227,165,153,119,38,184,180,124,17,68,146,217,35,32,137,46,55,63,209,91,149,188,207,205,144,135,151,178,220,252,190,97,242,86,211,171,20,42,93,158,132,60,57,83,71,109,65,162,31,45,67,216,183,123,164,118,196,23,73,236,127,12,111,246,108,161,59,82,41,157,85,170,251,96,134,177,187,204,62,90,203,89,95,176,156,169,160,81,11,245,22,235,122,117,44,215,79,174,213,233,230,231,173,232,116,214,244,234,168,80,88,175],J=[1,2,4,8,16,32,64,128,29,58,116,232,205,135,19,38,76,152,45,90,180,117,234,201,143,3,6,12,24,48,96,192,157,39,78,156,37,74,148,53,106,212,181,119,238,193,159,35,70,140,5,10,20,40,80,160,93,186,105,210,185,111,222,161,95,190,97,194,153,47,94,188,101,202,137,15,30,60,120,240,253,231,211,187,107,214,177,127,254,225,223,163,91,182,113,226,217,175,67,134,17,34,68,136,13,26,52,104,208,189,103,206,129,31,62,124,248,237,199,147,59,118,236,197,151,51,102,204,133,23,46,92,184,109,218,169,79,158,33,66,132,21,42,84,168,77,154,41,82,164,85,170,73,146,57,114,228,213,183,115,230,209,191,99,198,145,63,126,252,229,215,179,123,246,241,255,227,219,171,75,150,49,98,196,149,55,110,220,165,87,174,65,130,25,50,100,200,141,7,14,28,56,112,224,221,167,83,166,81,162,89,178,121,242,249,239,195,155,43,86,172,69,138,9,18,36,72,144,61,122,244,245,247,243,251,235,203,139,11,22,44,88,176,125,250,233,207,131,27,54,108,216,173,71,142,0],m=[],E=[],e=[],C=[],n=[],q,d,A,u,r,p,D=2,w=[];D=k.level||D;var F=k.id||null;if(!k.code){console.warn("没有找到code");return}if(regUtf.test(k.code)){k.code=this.UtF16to8(k.code)}if(F){const size=uni.upx2px(Number(k.size));var K=size||Math.min(F.width,F.height),ca=O(k.code),R=Math.round(K/(d+8)),W=R*(d+8),X=Math.floor((K-W)/2);K=W;var G=null;if(Object.prototype.toString.call(k.id)=='[object String]'){G=uni.createCanvasContext(k.id,k.ctx||null);}else if(Object.prototype.toString.call(k.id)=='[object Object]'){G=k.id;}else{console.warn("没有找到canvas id或者实列d!");return}G.clearRect(0,0,size,size);G.setFillStyle(k.bgColor||'#FFFFFF');G.fillRect(0,0,size,size);if(k.color){let S=k.color;let V=G.createLinearGradient(0,0,size,0);if(Object.prototype.toString.call(S)=='[object String]'){G.setFillStyle(S)}else if(Object.prototype.toString.call(S)=='[object Array]'){V.addColorStop(0,S[0]);V.addColorStop(1,S[1]);G.setFillStyle(V)}else{G.setFillStyle("#000000");console.warn("没有找到canvas id或者实列!")}}else{G.setFillStyle("#000000");}for(F=0;F{if(callback&&typeof callback==="function"&&typeof callback.nodeType!=="number"){callback({...res,id:k.id})}});}else console.warn("No canvas provided to draw QR code in!")}};class Graphics{constructor(k,l,v,z,H){this.width=l;this.height=v;this.quiet=Math.round(this.width/40);this.padding_width=this.border_size=0;this.area={width:l-2*this.padding_width-2*this.quiet,height:v-2*this.border_size,top:this.border_size-4,left:this.padding_width+this.quiet};this.ctx=k;this.fg=z;this.bg=H;};fillFgRect(k,l,v,z){this.FILLRECT(k,l,v,z,this.fg);};fillBgRect(k,l,v,z){this.FILLRECT(k,l,v,z,this.bg);};FILLRECT(k,l,v,z,H){this.ctx.setFillStyle(H);this.ctx.fillRect(k,l,v,z);}} \ No newline at end of file diff --git a/components/lf-code/lf-barcode.vue b/components/lf-code/lf-barcode.vue new file mode 100644 index 0000000..3b68bd9 --- /dev/null +++ b/components/lf-code/lf-barcode.vue @@ -0,0 +1,87 @@ + + \ No newline at end of file diff --git a/components/lf-code/lf-qrcode.vue b/components/lf-code/lf-qrcode.vue new file mode 100644 index 0000000..f5ec7c7 --- /dev/null +++ b/components/lf-code/lf-qrcode.vue @@ -0,0 +1,84 @@ + + \ No newline at end of file diff --git a/pages.json b/pages.json index 698c9b1..48797d8 100644 --- a/pages.json +++ b/pages.json @@ -790,6 +790,13 @@ "navigationBarTitleText": "热门活动", "navigationStyle": "custom" } + }, + { + "path" : "pages/user/member/code", + "style" : { + "navigationBarTitleText": "会员码", + "navigationStyle": "custom" + } } ], "globalStyle": { diff --git a/pages/user/member/code.vue b/pages/user/member/code.vue new file mode 100644 index 0000000..b5365ab --- /dev/null +++ b/pages/user/member/code.vue @@ -0,0 +1,199 @@ + + + + + +