🌈 style(eslint): add eslint rules
This commit is contained in:
@@ -4,5 +4,5 @@
|
||||
export const enum EnumSaleMode {
|
||||
Bulk = 0,
|
||||
Plate = 1,
|
||||
BulkCut = 2
|
||||
BulkCut = 2,
|
||||
}
|
||||
|
||||
@@ -1,86 +1,76 @@
|
||||
module.exports = function(lab1, lab2){
|
||||
|
||||
var rgb2labArray1 = lab1;
|
||||
var rgb2labArray2 = lab2;
|
||||
|
||||
var l1 = rgb2labArray1[0];
|
||||
var a1 = rgb2labArray1[1];
|
||||
var b1 = rgb2labArray1[2];
|
||||
|
||||
var l2 = rgb2labArray2[0];
|
||||
var a2 = rgb2labArray2[1];
|
||||
var b2 = rgb2labArray2[2];
|
||||
|
||||
|
||||
var avg_lp = (l1 + l2) / 2;
|
||||
var c1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2));
|
||||
var c2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2));
|
||||
var avg_c = (c1 + c2) / 2;
|
||||
var g = (1- Math.sqrt(Math.pow(avg_c, 7) / (Math.pow(avg_c, 7) + Math.pow(25, 7)))) / 2;
|
||||
|
||||
var a1p = a1 * (1 + g);
|
||||
var a2p = a2 * (1 + g);
|
||||
|
||||
var c1p = Math.sqrt(Math.pow(a1p, 2) + Math.pow(b1, 2));
|
||||
var c2p = Math.sqrt(Math.pow(a2p, 2) + Math.pow(b2, 2));
|
||||
|
||||
var avg_cp = (c1p + c2p) / 2;
|
||||
|
||||
var h1p = rad2deg(Math.atan2(b1, a1p));
|
||||
if(h1p < 0){
|
||||
|
||||
h1p = h1p + 360;
|
||||
}
|
||||
|
||||
var h2p = rad2deg(Math.atan2(b2, a2p));
|
||||
if(h2p < 0){
|
||||
|
||||
h2p = h2p + 360;
|
||||
}
|
||||
|
||||
var avg_hp = Math.abs(h1p - h2p) > 180 ? (h1p + h2p + 360) / 2 : (h1p + h1p) / 2;
|
||||
|
||||
var t = 1 - 0.17 * Math.cos(deg2rad(avg_hp - 30)) + 0.24 * Math.cos(deg2rad(2 * avg_hp)) + 0.32 * Math.cos(deg2rad(3 * avg_hp + 6)) - 0.2 * Math.cos(deg2rad(4 * avg_hp - 63))
|
||||
|
||||
var delta_hp = h2p - h1p;
|
||||
if(Math.abs(delta_hp) > 180){
|
||||
if (h2p <= h1p) {
|
||||
delta_hp += 360;
|
||||
}
|
||||
else {
|
||||
delta_hp -= 360;
|
||||
}
|
||||
}
|
||||
|
||||
var delta_lp = l2 - l1;
|
||||
var delta_cp = c2p - c1p;
|
||||
|
||||
delta_hp = 2 * Math.sqrt(c1p * c2p) * Math.sin(deg2rad(delta_hp) / 2);
|
||||
|
||||
var s_l = 1 + ((0.015 * Math.pow(avg_lp - 50, 2)) / Math.sqrt(20 + Math.pow(avg_lp - 50, 2)));
|
||||
var s_c = 1 + 0.045 * avg_cp
|
||||
var s_h = 1 + 0.015 * avg_cp * t;
|
||||
|
||||
var delta_ro = 30 * Math.exp( - (Math.pow((avg_hp - 275) / 25, 2)));
|
||||
var r_c = 2 * Math.sqrt(Math.pow(avg_cp, 7) / (Math.pow(avg_cp, 7) + Math.pow(25, 7)));
|
||||
var r_t = -r_c * Math.sin(2 * deg2rad(delta_ro));
|
||||
|
||||
var kl = 1, kc =1, kh = 1;
|
||||
module.exports = function(lab1, lab2) {
|
||||
const rgb2labArray1 = lab1
|
||||
const rgb2labArray2 = lab2
|
||||
|
||||
var delta_e = Math.sqrt(Math.pow(delta_lp / (kl * s_l), 2) + Math.pow(delta_cp / (kc * s_c), 2) + Math.pow(delta_hp / (kh * s_h), 2) + r_t * (delta_cp / (kc * s_c)) * (delta_hp / (kh * s_h)))
|
||||
const l1 = rgb2labArray1[0]
|
||||
const a1 = rgb2labArray1[1]
|
||||
const b1 = rgb2labArray1[2]
|
||||
|
||||
return delta_e
|
||||
|
||||
|
||||
function rad2deg(rad){
|
||||
|
||||
return 360 * rad / (2 * Math.PI);
|
||||
}
|
||||
function deg2rad(deg){
|
||||
|
||||
return (2 * Math.PI * deg) / 360;
|
||||
}
|
||||
const l2 = rgb2labArray2[0]
|
||||
const a2 = rgb2labArray2[1]
|
||||
const b2 = rgb2labArray2[2]
|
||||
|
||||
const avg_lp = (l1 + l2) / 2
|
||||
const c1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2))
|
||||
const c2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2))
|
||||
const avg_c = (c1 + c2) / 2
|
||||
const g = (1 - Math.sqrt(Math.pow(avg_c, 7) / (Math.pow(avg_c, 7) + Math.pow(25, 7)))) / 2
|
||||
|
||||
const a1p = a1 * (1 + g)
|
||||
const a2p = a2 * (1 + g)
|
||||
|
||||
const c1p = Math.sqrt(Math.pow(a1p, 2) + Math.pow(b1, 2))
|
||||
const c2p = Math.sqrt(Math.pow(a2p, 2) + Math.pow(b2, 2))
|
||||
|
||||
const avg_cp = (c1p + c2p) / 2
|
||||
|
||||
let h1p = rad2deg(Math.atan2(b1, a1p))
|
||||
if (h1p < 0) {
|
||||
h1p = h1p + 360
|
||||
}
|
||||
|
||||
let h2p = rad2deg(Math.atan2(b2, a2p))
|
||||
if (h2p < 0) {
|
||||
h2p = h2p + 360
|
||||
}
|
||||
|
||||
const avg_hp = Math.abs(h1p - h2p) > 180 ? (h1p + h2p + 360) / 2 : (h1p + h1p) / 2
|
||||
|
||||
const t = 1 - 0.17 * Math.cos(deg2rad(avg_hp - 30)) + 0.24 * Math.cos(deg2rad(2 * avg_hp)) + 0.32 * Math.cos(deg2rad(3 * avg_hp + 6)) - 0.2 * Math.cos(deg2rad(4 * avg_hp - 63))
|
||||
|
||||
let delta_hp = h2p - h1p
|
||||
if (Math.abs(delta_hp) > 180) {
|
||||
if (h2p <= h1p) {
|
||||
delta_hp += 360
|
||||
}
|
||||
else {
|
||||
delta_hp -= 360
|
||||
}
|
||||
}
|
||||
|
||||
const delta_lp = l2 - l1
|
||||
const delta_cp = c2p - c1p
|
||||
|
||||
delta_hp = 2 * Math.sqrt(c1p * c2p) * Math.sin(deg2rad(delta_hp) / 2)
|
||||
|
||||
const s_l = 1 + ((0.015 * Math.pow(avg_lp - 50, 2)) / Math.sqrt(20 + Math.pow(avg_lp - 50, 2)))
|
||||
const s_c = 1 + 0.045 * avg_cp
|
||||
const s_h = 1 + 0.015 * avg_cp * t
|
||||
|
||||
const delta_ro = 30 * Math.exp(-(Math.pow((avg_hp - 275) / 25, 2)))
|
||||
const r_c = 2 * Math.sqrt(Math.pow(avg_cp, 7) / (Math.pow(avg_cp, 7) + Math.pow(25, 7)))
|
||||
const r_t = -r_c * Math.sin(2 * deg2rad(delta_ro))
|
||||
|
||||
const kl = 1; const kc = 1; const kh = 1
|
||||
|
||||
const delta_e = Math.sqrt(Math.pow(delta_lp / (kl * s_l), 2) + Math.pow(delta_cp / (kc * s_c), 2) + Math.pow(delta_hp / (kh * s_h), 2) + r_t * (delta_cp / (kc * s_c)) * (delta_hp / (kh * s_h)))
|
||||
|
||||
return delta_e
|
||||
|
||||
function rad2deg(rad) {
|
||||
return 360 * rad / (2 * Math.PI)
|
||||
}
|
||||
function deg2rad(deg) {
|
||||
return (2 * Math.PI * deg) / 360
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ import XyzCom from './xyz'
|
||||
import ColorDiff from './colorDiff'
|
||||
|
||||
export const toRgb = (lab) => {
|
||||
let xyz = LabCom.xyz(lab)
|
||||
return XyzCom.rgb(xyz)
|
||||
const xyz = LabCom.xyz(lab)
|
||||
return XyzCom.rgb(xyz)
|
||||
}
|
||||
|
||||
export const Ediff = (lab1, lab2) => {
|
||||
return ColorDiff(lab1, lab2)
|
||||
}
|
||||
return ColorDiff(lab1, lab2)
|
||||
}
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
|
||||
var xyz = require('./xyz');
|
||||
const xyz = require('./xyz')
|
||||
|
||||
module.exports = {
|
||||
name: 'lab',
|
||||
min: [0,-100,-100],
|
||||
max: [100,100,100],
|
||||
channel: ['lightness', 'a', 'b'],
|
||||
alias: ['LAB', 'cielab'],
|
||||
name: 'lab',
|
||||
min: [0, -100, -100],
|
||||
max: [100, 100, 100],
|
||||
channel: ['lightness', 'a', 'b'],
|
||||
alias: ['LAB', 'cielab'],
|
||||
|
||||
xyz: function(lab) {
|
||||
var l = lab[0],
|
||||
a = lab[1],
|
||||
b = lab[2],
|
||||
x, y, z, y2;
|
||||
xyz(lab) {
|
||||
const l = lab[0]
|
||||
const a = lab[1]
|
||||
const b = lab[2]
|
||||
let x; let y; let z; let y2
|
||||
|
||||
if (l <= 8) {
|
||||
y = (l * 100) / 903.3;
|
||||
y2 = (7.787 * (y / 100)) + (16 / 116);
|
||||
} else {
|
||||
y = 100 * Math.pow((l + 16) / 116, 3);
|
||||
y2 = Math.pow(y / 100, 1/3);
|
||||
}
|
||||
if (l <= 8) {
|
||||
y = (l * 100) / 903.3
|
||||
y2 = (7.787 * (y / 100)) + (16 / 116)
|
||||
}
|
||||
else {
|
||||
y = 100 * Math.pow((l + 16) / 116, 3)
|
||||
y2 = Math.pow(y / 100, 1 / 3)
|
||||
}
|
||||
|
||||
x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3);
|
||||
x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3)
|
||||
|
||||
z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3);
|
||||
z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3)
|
||||
|
||||
return [x, y, z];
|
||||
}
|
||||
};
|
||||
return [x, y, z]
|
||||
},
|
||||
}
|
||||
|
||||
// extend xyz
|
||||
xyz.lab = function(xyz) {
|
||||
let x = xyz[0]
|
||||
let y = xyz[1]
|
||||
let z = xyz[2]
|
||||
let l; let a; let b
|
||||
|
||||
//extend xyz
|
||||
xyz.lab = function(xyz){
|
||||
var x = xyz[0],
|
||||
y = xyz[1],
|
||||
z = xyz[2],
|
||||
l, a, b;
|
||||
x /= 95.047
|
||||
y /= 100
|
||||
z /= 108.883
|
||||
|
||||
x /= 95.047;
|
||||
y /= 100;
|
||||
z /= 108.883;
|
||||
x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116)
|
||||
y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116)
|
||||
z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116)
|
||||
|
||||
x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
|
||||
y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
|
||||
z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
|
||||
l = (116 * y) - 16
|
||||
a = 500 * (x - y)
|
||||
b = 200 * (y - z)
|
||||
|
||||
l = (116 * y) - 16;
|
||||
a = 500 * (x - y);
|
||||
b = 200 * (y - z);
|
||||
|
||||
return [l, a, b];
|
||||
};
|
||||
return [l, a, b]
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
|
||||
|
||||
module.exports = {
|
||||
name: 'rgb',
|
||||
min: [0,0,0],
|
||||
max: [255,255,255],
|
||||
channel: ['red', 'green', 'blue'],
|
||||
alias: ['RGB']
|
||||
};
|
||||
name: 'rgb',
|
||||
min: [0, 0, 0],
|
||||
max: [255, 255, 255],
|
||||
channel: ['red', 'green', 'blue'],
|
||||
alias: ['RGB'],
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
|
||||
var rgb = require('./rgb');
|
||||
|
||||
var xyz = {
|
||||
name: 'xyz',
|
||||
min: [0,0,0],
|
||||
channel: ['X','Y','Z'],
|
||||
alias: ['XYZ', 'ciexyz', 'cie1931']
|
||||
};
|
||||
const rgb = require('./rgb')
|
||||
|
||||
const xyz = {
|
||||
name: 'xyz',
|
||||
min: [0, 0, 0],
|
||||
channel: ['X', 'Y', 'Z'],
|
||||
alias: ['XYZ', 'ciexyz', 'cie1931'],
|
||||
}
|
||||
|
||||
/**
|
||||
* Whitepoint reference values with observer/illuminant
|
||||
@@ -15,57 +14,55 @@ var xyz = {
|
||||
* http://en.wikipedia.org/wiki/Standard_illuminant
|
||||
*/
|
||||
xyz.whitepoint = {
|
||||
//1931 2°
|
||||
2: {
|
||||
//incadescent
|
||||
A:[109.85, 100, 35.585],
|
||||
// B:[],
|
||||
C: [98.074, 100, 118.232],
|
||||
D50: [96.422, 100, 82.521],
|
||||
D55: [95.682, 100, 92.149],
|
||||
//daylight
|
||||
D65: [95.045592705167, 100, 108.9057750759878],
|
||||
D75: [94.972, 100, 122.638],
|
||||
//flourescent
|
||||
// F1: [],
|
||||
F2: [99.187, 100, 67.395],
|
||||
// F3: [],
|
||||
// F4: [],
|
||||
// F5: [],
|
||||
// F6:[],
|
||||
F7: [95.044, 100, 108.755],
|
||||
// F8: [],
|
||||
// F9: [],
|
||||
// F10: [],
|
||||
F11: [100.966, 100, 64.370],
|
||||
// F12: [],
|
||||
E: [100,100,100]
|
||||
},
|
||||
|
||||
//1964 10°
|
||||
10: {
|
||||
//incadescent
|
||||
A:[111.144, 100, 35.200],
|
||||
C: [97.285, 100, 116.145],
|
||||
D50: [96.720, 100, 81.427],
|
||||
D55: [95.799, 100, 90.926],
|
||||
//daylight
|
||||
D65: [94.811, 100, 107.304],
|
||||
D75: [94.416, 100, 120.641],
|
||||
//flourescent
|
||||
F2: [103.280, 100, 69.026],
|
||||
F7: [95.792, 100, 107.687],
|
||||
F11: [103.866, 100, 65.627],
|
||||
E: [100,100,100]
|
||||
}
|
||||
};
|
||||
// 1931 2°
|
||||
2: {
|
||||
// incadescent
|
||||
A: [109.85, 100, 35.585],
|
||||
// B:[],
|
||||
C: [98.074, 100, 118.232],
|
||||
D50: [96.422, 100, 82.521],
|
||||
D55: [95.682, 100, 92.149],
|
||||
// daylight
|
||||
D65: [95.045592705167, 100, 108.9057750759878],
|
||||
D75: [94.972, 100, 122.638],
|
||||
// flourescent
|
||||
// F1: [],
|
||||
F2: [99.187, 100, 67.395],
|
||||
// F3: [],
|
||||
// F4: [],
|
||||
// F5: [],
|
||||
// F6:[],
|
||||
F7: [95.044, 100, 108.755],
|
||||
// F8: [],
|
||||
// F9: [],
|
||||
// F10: [],
|
||||
F11: [100.966, 100, 64.370],
|
||||
// F12: [],
|
||||
E: [100, 100, 100],
|
||||
},
|
||||
|
||||
// 1964 10°
|
||||
10: {
|
||||
// incadescent
|
||||
A: [111.144, 100, 35.200],
|
||||
C: [97.285, 100, 116.145],
|
||||
D50: [96.720, 100, 81.427],
|
||||
D55: [95.799, 100, 90.926],
|
||||
// daylight
|
||||
D65: [94.811, 100, 107.304],
|
||||
D75: [94.416, 100, 120.641],
|
||||
// flourescent
|
||||
F2: [103.280, 100, 69.026],
|
||||
F7: [95.792, 100, 107.687],
|
||||
F11: [103.866, 100, 65.627],
|
||||
E: [100, 100, 100],
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Top values are the whitepoint’s top values, default are D65
|
||||
*/
|
||||
xyz.max = xyz.whitepoint[2].D65;
|
||||
|
||||
xyz.max = xyz.whitepoint[2].D65
|
||||
|
||||
/**
|
||||
* Transform xyz to rgb
|
||||
@@ -74,39 +71,40 @@ xyz.max = xyz.whitepoint[2].D65;
|
||||
*
|
||||
* @return {Array} RGB values
|
||||
*/
|
||||
xyz.rgb = function (_xyz, white) {
|
||||
//FIXME: make sure we have to divide like this. Probably we have to replace matrix as well then
|
||||
white = white || xyz.whitepoint[2].E;
|
||||
xyz.rgb = function(_xyz, white) {
|
||||
// FIXME: make sure we have to divide like this. Probably we have to replace matrix as well then
|
||||
white = white || xyz.whitepoint[2].E
|
||||
|
||||
var x = _xyz[0] / white[0],
|
||||
y = _xyz[1] / white[1],
|
||||
z = _xyz[2] / white[2],
|
||||
r, g, b;
|
||||
const x = _xyz[0] / white[0]
|
||||
const y = _xyz[1] / white[1]
|
||||
const z = _xyz[2] / white[2]
|
||||
let r; let g; let b
|
||||
|
||||
// assume sRGB
|
||||
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
|
||||
r = (x * 3.240969941904521) + (y * -1.537383177570093) + (z * -0.498610760293);
|
||||
g = (x * -0.96924363628087) + (y * 1.87596750150772) + (z * 0.041555057407175);
|
||||
b = (x * 0.055630079696993) + (y * -0.20397695888897) + (z * 1.056971514242878);
|
||||
// assume sRGB
|
||||
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
|
||||
r = (x * 3.240969941904521) + (y * -1.537383177570093) + (z * -0.498610760293)
|
||||
g = (x * -0.96924363628087) + (y * 1.87596750150772) + (z * 0.041555057407175)
|
||||
b = (x * 0.055630079696993) + (y * -0.20397695888897) + (z * 1.056971514242878)
|
||||
|
||||
r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
|
||||
: r = (r * 12.92);
|
||||
r = r > 0.0031308
|
||||
? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
|
||||
: r = (r * 12.92)
|
||||
|
||||
g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
|
||||
: g = (g * 12.92);
|
||||
g = g > 0.0031308
|
||||
? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
|
||||
: g = (g * 12.92)
|
||||
|
||||
b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
|
||||
: b = (b * 12.92);
|
||||
b = b > 0.0031308
|
||||
? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
|
||||
: b = (b * 12.92)
|
||||
|
||||
r = Math.min(Math.max(0, r), 1);
|
||||
g = Math.min(Math.max(0, g), 1);
|
||||
b = Math.min(Math.max(0, b), 1);
|
||||
r = Math.min(Math.max(0, r), 1)
|
||||
g = Math.min(Math.max(0, g), 1)
|
||||
b = Math.min(Math.max(0, b), 1)
|
||||
|
||||
return [r * 255, g * 255, b * 255];
|
||||
return [r * 255, g * 255, b * 255]
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* RGB to XYZ
|
||||
*
|
||||
@@ -115,24 +113,22 @@ xyz.rgb = function (_xyz, white) {
|
||||
* @return {Array} XYZ channels
|
||||
*/
|
||||
rgb.xyz = function(rgb, white) {
|
||||
var r = rgb[0] / 255,
|
||||
g = rgb[1] / 255,
|
||||
b = rgb[2] / 255;
|
||||
let r = rgb[0] / 255
|
||||
let g = rgb[1] / 255
|
||||
let b = rgb[2] / 255
|
||||
|
||||
// assume sRGB
|
||||
r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
|
||||
g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
|
||||
b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
|
||||
// assume sRGB
|
||||
r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92)
|
||||
g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92)
|
||||
b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92)
|
||||
|
||||
var x = (r * 0.41239079926595) + (g * 0.35758433938387) + (b * 0.18048078840183);
|
||||
var y = (r * 0.21263900587151) + (g * 0.71516867876775) + (b * 0.072192315360733);
|
||||
var z = (r * 0.019330818715591) + (g * 0.11919477979462) + (b * 0.95053215224966);
|
||||
const x = (r * 0.41239079926595) + (g * 0.35758433938387) + (b * 0.18048078840183)
|
||||
const y = (r * 0.21263900587151) + (g * 0.71516867876775) + (b * 0.072192315360733)
|
||||
const z = (r * 0.019330818715591) + (g * 0.11919477979462) + (b * 0.95053215224966)
|
||||
|
||||
white = white || xyz.whitepoint[2].E;
|
||||
white = white || xyz.whitepoint[2].E
|
||||
|
||||
return [x * white[0], y * white[1], z * white[2]];
|
||||
};
|
||||
return [x * white[0], y * white[1], z * white[2]]
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports = xyz;
|
||||
module.exports = xyz
|
||||
|
||||
+97
-102
@@ -1,146 +1,141 @@
|
||||
import { uint32ToUint8Array, uint8ArrayToHex } from "./utils";
|
||||
import { uint32ToUint8Array, uint8ArrayToHex } from './utils'
|
||||
|
||||
export class Command {
|
||||
// 测量序号
|
||||
static measureId = 1;
|
||||
// 测量序号
|
||||
static measureId = 1
|
||||
|
||||
// 命令完整响应的长度
|
||||
responseSize = 0;
|
||||
// 命令发送的数据
|
||||
content = new Uint8Array(0);
|
||||
// 命令响应的数据
|
||||
response = new Uint8Array(0);
|
||||
// 等待响应的超时时间
|
||||
timeout = 3000;
|
||||
// 发送的数据是否需要生成和校验值
|
||||
needSign = true;
|
||||
|
||||
// 命令完整响应的长度
|
||||
responseSize = 0
|
||||
// 命令发送的数据
|
||||
content = new Uint8Array(0)
|
||||
// 命令响应的数据
|
||||
response = new Uint8Array(0)
|
||||
// 等待响应的超时时间
|
||||
timeout = 3000
|
||||
// 发送的数据是否需要生成和校验值
|
||||
needSign = true
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param {Uint8Array|ArrayBuffer|number[]} content
|
||||
* @param {number} responseSize
|
||||
* @param {number} timeout
|
||||
* @param {number} responseSize
|
||||
* @param {number} timeout
|
||||
* @param {boolean} needSign
|
||||
*/
|
||||
constructor(content, responseSize, timeout = 3000, needSign = true) {
|
||||
if (content instanceof Uint8Array) {
|
||||
this.content = content;
|
||||
} else {
|
||||
this.content = new Uint8Array(content);
|
||||
}
|
||||
this.responseSize = responseSize;
|
||||
if (typeof timeout === 'number' && timeout >= 0) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
this.needSign = needSign;
|
||||
constructor(content, responseSize, timeout = 3000, needSign = true) {
|
||||
if (content instanceof Uint8Array) {
|
||||
this.content = content
|
||||
}
|
||||
else {
|
||||
this.content = new Uint8Array(content)
|
||||
}
|
||||
|
||||
/**
|
||||
this.responseSize = responseSize
|
||||
if (typeof timeout === 'number' && timeout >= 0) {
|
||||
this.timeout = timeout
|
||||
}
|
||||
this.needSign = needSign
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回一个 ArrayBuffer 数组, 用于发送
|
||||
* @returns {ArrayBuffer[]}
|
||||
*/
|
||||
get data() {
|
||||
if (this.content.length === 0) throw new Error('正文内容不能为空');
|
||||
const data = [];
|
||||
const b = new Uint8Array(this.content.buffer);
|
||||
if (this.needSign) {
|
||||
b[b.length - 1] = Command.getSign(b);
|
||||
}
|
||||
for (let i = 0; i < b.length; i += 20) {
|
||||
data.push(b.slice(i, i + 20).buffer);
|
||||
}
|
||||
return data;
|
||||
get data() {
|
||||
if (this.content.length === 0) { throw new Error('正文内容不能为空') }
|
||||
const data = []
|
||||
const b = new Uint8Array(this.content.buffer)
|
||||
if (this.needSign) {
|
||||
b[b.length - 1] = Command.getSign(b)
|
||||
}
|
||||
|
||||
/** 是否接收完成 */
|
||||
get isComplete() {
|
||||
return this.response.length >= this.responseSize;
|
||||
for (let i = 0; i < b.length; i += 20) {
|
||||
data.push(b.slice(i, i + 20).buffer)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
/** 是否有效 */
|
||||
get isValid() {
|
||||
return Command.getSign(this.response) === this.response[this.response.length - 1];
|
||||
}
|
||||
/** 是否接收完成 */
|
||||
get isComplete() {
|
||||
return this.response.length >= this.responseSize
|
||||
}
|
||||
|
||||
/**
|
||||
/** 是否有效 */
|
||||
get isValid() {
|
||||
return Command.getSign(this.response) === this.response[this.response.length - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充响应数组
|
||||
* @param {ArrayBuffer} buffer
|
||||
* @param {ArrayBuffer} buffer
|
||||
*/
|
||||
fillResponse(buffer) {
|
||||
this.response = new Uint8Array([...this.response, ...(new Uint8Array(buffer))]);
|
||||
}
|
||||
fillResponse(buffer) {
|
||||
this.response = new Uint8Array([...this.response, ...(new Uint8Array(buffer))])
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* 获取和校验值
|
||||
* @param {ArrayBuffer|Uint8Array} buffer
|
||||
* @param {ArrayBuffer|Uint8Array} buffer
|
||||
*/
|
||||
static getSign(buffer) {
|
||||
const _b = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
||||
let sum = 0;
|
||||
_b.slice(0, _b.length - 1).forEach(i => sum += i);
|
||||
return new Uint8Array([sum])[0];
|
||||
}
|
||||
static getSign(buffer) {
|
||||
const _b = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer)
|
||||
let sum = 0
|
||||
_b.slice(0, _b.length - 1).forEach(i => sum += i)
|
||||
return new Uint8Array([sum])[0]
|
||||
}
|
||||
|
||||
// 唤醒命令
|
||||
static WakeUp = new Command([0xf0], 0, 0, false);
|
||||
// 唤醒命令
|
||||
static WakeUp = new Command([0xF0], 0, 0, false)
|
||||
|
||||
/**
|
||||
/**
|
||||
* 获取测量命令
|
||||
* @param {number} mode
|
||||
* @param {number} mode
|
||||
*/
|
||||
static measure(mode = 0) {
|
||||
Command.measureId += 1;
|
||||
const measureId = uint32ToUint8Array(Command.measureId);
|
||||
return new Command([0xbb, 1, mode, ...measureId, 0, 0xff, 0], 10, 1500);
|
||||
}
|
||||
static measure(mode = 0) {
|
||||
Command.measureId += 1
|
||||
const measureId = uint32ToUint8Array(Command.measureId)
|
||||
return new Command([0xBB, 1, mode, ...measureId, 0, 0xFF, 0], 10, 1500)
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 获取测量数据 (Lab)
|
||||
* @param {number} mode
|
||||
* @param {number} mode
|
||||
*/
|
||||
static getLab(mode = 0) {
|
||||
return new Command([0xbb, 3, mode, 0, 0, 0, 0, 0, 0xff, 0], 20, 1500);
|
||||
}
|
||||
static getLab(mode = 0) {
|
||||
return new Command([0xBB, 3, mode, 0, 0, 0, 0, 0, 0xFF, 0], 20, 1500)
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 获取测量数据 (RGB)
|
||||
* @param {number} mode
|
||||
* @param {number} mode
|
||||
*/
|
||||
static getRGB(mode = 0) {
|
||||
return new Command([0xbb, 4, mode, 0, 0, 0, 0, 0, 0xff, 0], 20, 1500);
|
||||
}
|
||||
static getRGB(mode = 0) {
|
||||
return new Command([0xBB, 4, mode, 0, 0, 0, 0, 0, 0xFF, 0], 20, 1500)
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 获取测量的光谱数据
|
||||
* @param {number} mode
|
||||
*/
|
||||
static getSpectral(mode = 0) {
|
||||
return new Command([0xbb, 2, 0x10 + mode, 0, 0, 0 ,0 ,0, 0xff, 0], 200, 5000);
|
||||
}
|
||||
static getSpectral(mode = 0) {
|
||||
return new Command([0xBB, 2, 0x10 + mode, 0, 0, 0, 0, 0, 0xFF, 0], 200, 5000)
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 白校准
|
||||
* @param {number} check 是否判断校准成功 1 判断 0 不判断
|
||||
*/
|
||||
static whiteCalibrate(check = 1) {
|
||||
return new Command([0xbb, 0x11, check, 0, 0, 0, 0, 0, 0xff, 0], 10, 1500);
|
||||
}
|
||||
static whiteCalibrate(check = 1) {
|
||||
return new Command([0xBB, 0x11, check, 0, 0, 0, 0, 0, 0xFF, 0], 10, 1500)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* 黑校准
|
||||
* @param {number} check 是否判断校准成功
|
||||
*/
|
||||
static blackCalibrate(check = 1) {
|
||||
return new Command([0xbb, 0x10, check, 0, 0, 0, 0, 0, 0xff, 0], 10, 1500);
|
||||
}
|
||||
static blackCalibrate(check = 1) {
|
||||
return new Command([0xBB, 0x10, check, 0, 0, 0, 0, 0, 0xFF, 0], 10, 1500)
|
||||
}
|
||||
|
||||
/** 获取校准状态 */
|
||||
static GetCalibrationInf = new Command([0xBB, 0x1E, 0, 0, 0, 0, 0, 0, 0xFF, 0], 20, 1500)
|
||||
|
||||
/** 获取校准状态 */
|
||||
static GetCalibrationInf = new Command([0xbb, 0x1e, 0, 0, 0, 0, 0, 0, 0xff, 0], 20, 1500);
|
||||
|
||||
|
||||
|
||||
static GetDeviceInf = new Command([0xbb, 0x12, 0x01, 0, 0, 0, 0, 0, 0xff, 0], 200, 5000);
|
||||
}
|
||||
static GetDeviceInf = new Command([0xBB, 0x12, 0x01, 0, 0, 0, 0, 0, 0xFF, 0], 200, 5000)
|
||||
}
|
||||
|
||||
@@ -1,70 +1,65 @@
|
||||
/**
|
||||
* Uint32 转 Uint8 数组
|
||||
* @param {number} n
|
||||
* @param {number} n
|
||||
*/
|
||||
export function uint32ToUint8Array(n) {
|
||||
return new Uint8Array(new Uint32Array([n]).buffer);
|
||||
return new Uint8Array(new Uint32Array([n]).buffer)
|
||||
}
|
||||
|
||||
/**
|
||||
* Uint8 数组 转 Float32
|
||||
* @param {Uint8Array} raw
|
||||
* @param {Uint8Array} raw
|
||||
*/
|
||||
export function uint8ArrayToFloat32(raw) {
|
||||
return new Float32Array(raw.buffer)[0];
|
||||
return new Float32Array(raw.buffer)[0]
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uint8 数组 转 Uint16
|
||||
* @param {Uint8Array} raw
|
||||
* @param {Uint8Array} raw
|
||||
*/
|
||||
export function uint8ArrayToUint16(raw) {
|
||||
return new Uint16Array(raw.buffer)[0];
|
||||
return new Uint16Array(raw.buffer)[0]
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uint8 数组转 Uint32
|
||||
* @param {Uint8Array} raw
|
||||
* @returns
|
||||
* @param {Uint8Array} raw
|
||||
* @returns
|
||||
*/
|
||||
export function uint8ArrayToUnit32(raw) {
|
||||
return new Uint32Array(raw.buffer)[0];
|
||||
return new Uint32Array(raw.buffer)[0]
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 等待指定时长
|
||||
* @param {number} duration
|
||||
* @param {number} duration
|
||||
*/
|
||||
export function waitFor(duration) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, duration);
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, duration)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* uint8 数组转 hex 字符串
|
||||
* @param {Uint8Array} raw
|
||||
* @param {Uint8Array} raw
|
||||
*/
|
||||
export function uint8ArrayToHex(raw) {
|
||||
const s = [];
|
||||
raw.forEach(i => {
|
||||
const b = i.toString(16);
|
||||
s.push(b.length > 1 ? b : `0${b}`);
|
||||
});
|
||||
return s.join(' ');
|
||||
const s = []
|
||||
raw.forEach((i) => {
|
||||
const b = i.toString(16)
|
||||
s.push(b.length > 1 ? b : `0${b}`)
|
||||
})
|
||||
return s.join(' ')
|
||||
}
|
||||
|
||||
|
||||
// 二进制转字符串(ascii)
|
||||
export function bufferToString(buffer) {
|
||||
let str = "";
|
||||
for (let code of buffer) {
|
||||
if (code === 0) break;
|
||||
str += utf82string(code);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
let str = ''
|
||||
for (const code of buffer) {
|
||||
if (code === 0) { break }
|
||||
str += utf82string(code)
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
+56
-51
@@ -10,9 +10,9 @@ import Qs from 'qs'
|
||||
type ParamLink = 'navigateTo' | 'switchTab' | 'reLaunch' | 'redirectTo'
|
||||
export const goLink = (path = '', params = {}, way: ParamLink = 'navigateTo') => {
|
||||
if (path) {
|
||||
let params_str = Qs.stringify(params)
|
||||
const params_str = Qs.stringify(params)
|
||||
console.log('params_str==>', params_str)
|
||||
path = params_str ? path + '?' + params_str : path
|
||||
path = params_str ? `${path}?${params_str}` : path
|
||||
Taro[way]({ url: path })
|
||||
}
|
||||
}
|
||||
@@ -24,12 +24,15 @@ export const goLink = (path = '', params = {}, way: ParamLink = 'navigateTo') =>
|
||||
export const isEmptyObject = (object: any) => {
|
||||
if (object == undefined || object == null || Number.isNaN(object)) {
|
||||
return true
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (object.constructor == Object) {
|
||||
return Reflect.ownKeys(object).length == 0
|
||||
} else if (object.constructor == Array) {
|
||||
}
|
||||
else if (object.constructor == Array) {
|
||||
return object.length == 0
|
||||
} else if (object.constructor == String) {
|
||||
}
|
||||
else if (object.constructor == String) {
|
||||
return object == ''
|
||||
}
|
||||
}
|
||||
@@ -38,7 +41,7 @@ export const isEmptyObject = (object: any) => {
|
||||
|
||||
/**
|
||||
* 表单检索
|
||||
* @param data
|
||||
* @param data
|
||||
* @param rules = {
|
||||
account: [{
|
||||
message: "请输入正确的用户名",
|
||||
@@ -52,45 +55,48 @@ export const isEmptyObject = (object: any) => {
|
||||
// regex: /\d/
|
||||
}]
|
||||
};
|
||||
* @param message
|
||||
* @returns
|
||||
* @param message
|
||||
* @returns
|
||||
*/
|
||||
export const retrieval = (data: any, rules?: Object, message: string = '请填写完信息') => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (rules) {
|
||||
const keys = Reflect.ownKeys(rules)
|
||||
const result = keys.some((key: any) => {
|
||||
for (let item of (rules as any)[key]) {
|
||||
let _res = false
|
||||
if (item.validator) {
|
||||
if (item.validator(data[key], item)) {
|
||||
_res = true
|
||||
}
|
||||
} else if (item.regex) {
|
||||
if (!item.regex.test(data[key])) {
|
||||
_res = true
|
||||
}
|
||||
} else {
|
||||
if (isEmptyObject(data[key])) {
|
||||
_res = true
|
||||
}
|
||||
}
|
||||
message = item.message
|
||||
return _res
|
||||
}
|
||||
})
|
||||
if (result) {
|
||||
reject(message)
|
||||
}
|
||||
} else {
|
||||
const keys = Reflect.ownKeys(data)
|
||||
if (keys.some((key: any) => isEmptyObject(data[key]))) {
|
||||
reject(message)
|
||||
}
|
||||
}
|
||||
resolve(null)
|
||||
})
|
||||
}
|
||||
// export const retrieval = (data: any, rules?: Object, message = '请填写完信息') => {
|
||||
// return new Promise((resolve, reject) => {
|
||||
// if (rules) {
|
||||
// const keys = Reflect.ownKeys(rules)
|
||||
// const result = keys.some((key: any) => {
|
||||
// for (const item of (rules as any)[key]) {
|
||||
// let _res = false
|
||||
// if (item.validator) {
|
||||
// if (item.validator(data[key], item)) {
|
||||
// _res = true
|
||||
// }
|
||||
// }
|
||||
// else if (item.regex) {
|
||||
// if (!item.regex.test(data[key])) {
|
||||
// _res = true
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// if (isEmptyObject(data[key])) {
|
||||
// _res = true
|
||||
// }
|
||||
// }
|
||||
// message = item.message
|
||||
// return _res
|
||||
// }
|
||||
// })
|
||||
// if (result) {
|
||||
// reject(message)
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// const keys = Reflect.ownKeys(data)
|
||||
// if (keys.some((key: any) => isEmptyObject(data[key]))) {
|
||||
// reject(message)
|
||||
// }
|
||||
// }
|
||||
// resolve(null)
|
||||
// })
|
||||
// }
|
||||
/**
|
||||
* toast提示
|
||||
*/
|
||||
@@ -107,7 +113,7 @@ export const alert = {
|
||||
icon: 'error',
|
||||
})
|
||||
},
|
||||
loading(title: string, mask: boolean = false) {
|
||||
loading(title: string, mask = false) {
|
||||
Taro.showToast({
|
||||
title,
|
||||
icon: 'loading',
|
||||
@@ -120,7 +126,7 @@ export const alert = {
|
||||
icon: 'none',
|
||||
})
|
||||
},
|
||||
showLoading(title: string, mask: boolean = true) {
|
||||
showLoading(title: string, mask = true) {
|
||||
Taro.showLoading({ title, mask })
|
||||
},
|
||||
hideLoading() {
|
||||
@@ -143,13 +149,12 @@ export const formatKbPrice = (number: string) => {
|
||||
return ret.reverse().join('')
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证权限
|
||||
* @param {权限key} key
|
||||
* @returns
|
||||
*/
|
||||
export const checkKey = (key = "") => {
|
||||
let getUser = JSON.parse(Taro.getStorageSync("userInfo"));
|
||||
return getUser.mp_role_access_list?.includes(key);
|
||||
};
|
||||
export const checkKey = (key = '') => {
|
||||
const getUser = JSON.parse(Taro.getStorageSync('userInfo'))
|
||||
return getUser.mp_role_access_list?.includes(key)
|
||||
}
|
||||
|
||||
+10
-10
@@ -19,30 +19,30 @@ export const BASE_URL = CURRENT_BASE_URL
|
||||
|
||||
// CDN
|
||||
// 生成密钥
|
||||
export const GET_UPLOAD_SIGN = `/upyun/getsign` // 请求签名 url
|
||||
export const UPLOAD_CDN_URL = `https://v0.api.upyun.com/`
|
||||
export const GET_UPLOAD_SIGN = '/upyun/getsign' // 请求签名 url
|
||||
export const UPLOAD_CDN_URL = 'https://v0.api.upyun.com/'
|
||||
|
||||
// cdn
|
||||
export const IMG_CND_Prefix = CURRENT_ENV.includes('production') ? 'https://cdn.zzfzyc.com' : 'https://test.cdn.zzfzyc.com'
|
||||
|
||||
//在线支付图片baseUrl
|
||||
// 在线支付图片baseUrl
|
||||
export const CAP_HTML_TO_IMAGE_BASE_URL = CURRENT_ENV.includes('production') ? 'https://www.zzfzyc.com' : 'https://test.zzfzyc.com'
|
||||
|
||||
// 上传图片视频
|
||||
export const CDN_UPLOAD_IMG = `${UPLOAD_CDN_URL || ''}`
|
||||
|
||||
//appid
|
||||
// appid
|
||||
export const WX_APPID = 'wx64fe67f111d52457'
|
||||
|
||||
export const LIST_EMPTY_IMAGE = IMG_CND_Prefix + '/list_empty.png'
|
||||
export const LIST_EMPTY_IMAGE = `${IMG_CND_Prefix}/list_empty.png`
|
||||
|
||||
export const EMPTY_IMAGE = IMG_CND_Prefix + '/empty.png'
|
||||
export const EMPTY_IMAGE = `${IMG_CND_Prefix}/empty.png`
|
||||
|
||||
export const SEARCH_EMPTY_IMAGE = IMG_CND_Prefix + '/search_empty.png'
|
||||
export const SEARCH_EMPTY_IMAGE = `${IMG_CND_Prefix}/search_empty.png`
|
||||
|
||||
//场景值
|
||||
// 场景值
|
||||
export const SCENE = {
|
||||
SearchScene: 0, //商城面料搜索
|
||||
SearchScene: 0, // 商城面料搜索
|
||||
}
|
||||
//支付码单跳转链接
|
||||
// 支付码单跳转链接
|
||||
export const PAY_H5_CODE_URL = CURRENT_ENV.includes('production') ? 'https://www.zzfzyc.com/cashier' : 'https://test.zzfzyc.com/cashier'
|
||||
|
||||
+51
-52
@@ -1,73 +1,72 @@
|
||||
|
||||
//订单状态枚举
|
||||
// 订单状态枚举
|
||||
export const ORDER_STATUS = {
|
||||
SaleorderstatusWaitingPrePayment : {value:10, label:'预付款'}, // 预付款
|
||||
SaleOrderStatusBooking : {value:0, label:'待接单'}, // 待接单
|
||||
SaleOrderStatusArranging : {value:1, label:'配布中'}, // 配布中
|
||||
SaleOrderStatusArranged : {value:2, label:'已配布'}, // 已配布
|
||||
SaleOrderStatusWaitingPayment : {value:7, label:'待付款'}, // 待付款
|
||||
SaleOrderStatusTaking: {value: 11, label:'提货中'}, //提货中
|
||||
SaleOrderStatusWaitingDelivery : {value:3, label:'待发货'}, // 待发货
|
||||
SaleOrderStatusWaitingReceipt : {value:8, label:'待收货'}, // 待收货
|
||||
SaleOrderStatusAlreadyReceipt : {value:9, label:'已收货'}, // 已收货
|
||||
SaleOrderStatusComplete : {value:4, label:'已完成'}, // 已完成
|
||||
SaleOrderStatusRefund : {value:6, label:'已退款'}, // 已退款
|
||||
SaleOrderStatusCancel : {value:5, label:'已取消'}, // 已取消
|
||||
SaleorderstatusWaitingPrePayment: { value: 10, label: '预付款' }, // 预付款
|
||||
SaleOrderStatusBooking: { value: 0, label: '待接单' }, // 待接单
|
||||
SaleOrderStatusArranging: { value: 1, label: '配布中' }, // 配布中
|
||||
SaleOrderStatusArranged: { value: 2, label: '已配布' }, // 已配布
|
||||
SaleOrderStatusWaitingPayment: { value: 7, label: '待付款' }, // 待付款
|
||||
SaleOrderStatusTaking: { value: 11, label: '提货中' }, // 提货中
|
||||
SaleOrderStatusWaitingDelivery: { value: 3, label: '待发货' }, // 待发货
|
||||
SaleOrderStatusWaitingReceipt: { value: 8, label: '待收货' }, // 待收货
|
||||
SaleOrderStatusAlreadyReceipt: { value: 9, label: '已收货' }, // 已收货
|
||||
SaleOrderStatusComplete: { value: 4, label: '已完成' }, // 已完成
|
||||
SaleOrderStatusRefund: { value: 6, label: '已退款' }, // 已退款
|
||||
SaleOrderStatusCancel: { value: 5, label: '已取消' }, // 已取消
|
||||
}
|
||||
|
||||
//售后单状态枚举
|
||||
// 售后单状态枚举
|
||||
export const AFTER_ORDER_STATUS = {
|
||||
ReturnStageApplying : {value:0, label:'申请中'}, // 申请中
|
||||
ReturnStageWaitCheck : {value:1, label:'退货中'}, // 退货中
|
||||
ReturnStageChecked : {value:2, label:'待验布'}, // 待验布
|
||||
ReturnStageReturned : {value:3, label:'已退款'}, // 已退款
|
||||
ReturnStageCancel : {value:4, label:'已取消'}, // 已取消
|
||||
ReturnStageQualityCheckPendingRefund : {value:5, label:'待退款'}, // 已验布
|
||||
ReturnStageServiceOrderPendingRefund : {value:6, label:'待退款'}, // 待退款
|
||||
ReturnStageRejected : {value:7, label:'已拒绝'}, // 已拒绝
|
||||
ReturnStageApplying: { value: 0, label: '申请中' }, // 申请中
|
||||
ReturnStageWaitCheck: { value: 1, label: '退货中' }, // 退货中
|
||||
ReturnStageChecked: { value: 2, label: '待验布' }, // 待验布
|
||||
ReturnStageReturned: { value: 3, label: '已退款' }, // 已退款
|
||||
ReturnStageCancel: { value: 4, label: '已取消' }, // 已取消
|
||||
ReturnStageQualityCheckPendingRefund: { value: 5, label: '待退款' }, // 已验布
|
||||
ReturnStageServiceOrderPendingRefund: { value: 6, label: '待退款' }, // 待退款
|
||||
ReturnStageRejected: { value: 7, label: '已拒绝' }, // 已拒绝
|
||||
}
|
||||
|
||||
//支付方式
|
||||
// 支付方式
|
||||
export const PAYMENT_METHOD = {
|
||||
PaymentMethodPreDeposit: {value:2, label:'预存款'},
|
||||
PaymentMethodAccountPeriod : {value:3, label:'账期'},
|
||||
PaymentMethodofflineRemittance: {value:1, label:'线下汇款'},
|
||||
PaymentMethodScanCodeToPay: {value:4, label:'扫码支付'},
|
||||
PaymentMethodCashOnDelivery: {value:5, label:'货到付款'},
|
||||
PaymentMethodPreDeposit: { value: 2, label: '预存款' },
|
||||
PaymentMethodAccountPeriod: { value: 3, label: '账期' },
|
||||
PaymentMethodofflineRemittance: { value: 1, label: '线下汇款' },
|
||||
PaymentMethodScanCodeToPay: { value: 4, label: '扫码支付' },
|
||||
PaymentMethodCashOnDelivery: { value: 5, label: '货到付款' },
|
||||
}
|
||||
|
||||
|
||||
//订单类型
|
||||
// 订单类型
|
||||
export const SALE_MODE = {
|
||||
SaLeModeBulk: {value:0, label:'大货'},
|
||||
SaleModeLengthCut: {value:1, label:'剪版'},
|
||||
SaLeModeWeightCut: {value:2, label:'散剪'},
|
||||
}
|
||||
SaLeModeBulk: { value: 0, label: '大货' },
|
||||
SaleModeLengthCut: { value: 1, label: '剪版' },
|
||||
SaLeModeWeightCut: { value: 2, label: '散剪' },
|
||||
}
|
||||
|
||||
//分享场景枚举
|
||||
// 分享场景枚举
|
||||
export const SHARE_SCENE = {
|
||||
ShareDetail: {value:1, label:'详情分享'},
|
||||
SharePage : {value:2, label:'页面分享'},
|
||||
ShareDetail: { value: 1, label: '详情分享' },
|
||||
SharePage: { value: 2, label: '页面分享' },
|
||||
}
|
||||
|
||||
//订阅消息
|
||||
export const SUBSCRIPTION_MESSAGE_SCENE = {
|
||||
SubmitOrder: {value:1, label:'确认下单'},
|
||||
ToPay : {value:2, label:'去付款'},
|
||||
ApplyGoods: {value:3, label: '申请退款'}
|
||||
// 订阅消息
|
||||
export const SUBSCRIPTION_MESSAGE_SCENE = {
|
||||
SubmitOrder: { value: 1, label: '确认下单' },
|
||||
ToPay: { value: 2, label: '去付款' },
|
||||
ApplyGoods: { value: 3, label: '申请退款' },
|
||||
}
|
||||
|
||||
//应收单退款状态枚举
|
||||
// 应收单退款状态枚举
|
||||
export const REFUND_STATUS = {
|
||||
ShouldCollectOrderRefundTypeUnknown: {value:0, label:'未知退款'},
|
||||
ShouldCollectOrderRefundTypeAdvanceReceiptRefund: {value:1, label:'预收退款'},
|
||||
ShouldCollectOrderRefundTypeReturnForRefund: {value:2, label:'退货退款'},
|
||||
ShouldCollectOrderRefundTypeSalesRefund: {value:3, label:'销售退款'},
|
||||
ShouldCollectOrderRefundTypeUnknown: { value: 0, label: '未知退款' },
|
||||
ShouldCollectOrderRefundTypeAdvanceReceiptRefund: { value: 1, label: '预收退款' },
|
||||
ShouldCollectOrderRefundTypeReturnForRefund: { value: 2, label: '退货退款' },
|
||||
ShouldCollectOrderRefundTypeSalesRefund: { value: 3, label: '销售退款' },
|
||||
}
|
||||
|
||||
//申请单退款状态枚举
|
||||
// 申请单退款状态枚举
|
||||
export const REFUND_STATUS_ORDER = {
|
||||
ReturnApplyOrderTypeAdvanceReceiptRefund: {value:2, label:'预收退款'}, // 预收退款
|
||||
ReturnApplyOrderTypeReturnForRefund: {value:1, label:'退货退款'}, // 退货退款
|
||||
ReturnApplyOrderTypeSalesRefund: {value:3, label:'销售退款'}, // 销售退款
|
||||
}
|
||||
ReturnApplyOrderTypeAdvanceReceiptRefund: { value: 2, label: '预收退款' }, // 预收退款
|
||||
ReturnApplyOrderTypeReturnForRefund: { value: 1, label: '退货退款' }, // 退货退款
|
||||
ReturnApplyOrderTypeSalesRefund: { value: 3, label: '销售退款' }, // 销售退款
|
||||
}
|
||||
|
||||
+61
-47
@@ -20,7 +20,8 @@ export const formatRemoveHashTag = (val = '') => {
|
||||
export const formatHashTag = (code = '', name = '', mode = 'both') => {
|
||||
if (mode == 'both') {
|
||||
return `${formatRemoveHashTag(code)}# ${name}`
|
||||
} else if (mode == 'name') {
|
||||
}
|
||||
else if (mode == 'name') {
|
||||
return `${name}`
|
||||
}
|
||||
}
|
||||
@@ -45,7 +46,7 @@ export const meterDigit = 100
|
||||
* @returns
|
||||
*/
|
||||
export const formatPriceDiv = (val, digit = Digit, priceStatus = false) => {
|
||||
let res = strip(Number(val / digit)) || 0
|
||||
const res = strip(Number(val / digit)) || 0
|
||||
return priceStatus ? numberWithCommas({ number: res }) : res
|
||||
}
|
||||
/**
|
||||
@@ -94,13 +95,13 @@ export const formatWeightDiv = (val, digit = weightDigit) => {
|
||||
|
||||
export const formatDateTime = (val, fmt = 'YYYY-MM-DD HH:mm:ss') => {
|
||||
if (val) {
|
||||
let time = new Date(val)
|
||||
let Y = time.getFullYear()
|
||||
let M = time.getMonth() + 1
|
||||
let d = time.getDate()
|
||||
let h = time.getHours()
|
||||
let m = time.getMinutes()
|
||||
let s = time.getSeconds()
|
||||
const time = new Date(val)
|
||||
const Y = time.getFullYear()
|
||||
const M = time.getMonth() + 1
|
||||
const d = time.getDate()
|
||||
const h = time.getHours()
|
||||
const m = time.getMinutes()
|
||||
const s = time.getSeconds()
|
||||
|
||||
fmt = fmt
|
||||
.replace('YYYY', Y)
|
||||
@@ -111,7 +112,8 @@ export const formatDateTime = (val, fmt = 'YYYY-MM-DD HH:mm:ss') => {
|
||||
.replace('ss', s.toString().padStart(2, '0'))
|
||||
|
||||
return fmt
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return val
|
||||
}
|
||||
}
|
||||
@@ -141,18 +143,19 @@ export const formatMillionYuan = (num, digit = 10000) => {
|
||||
* @param {*} x
|
||||
* @returns
|
||||
*/
|
||||
export const toDecimal2 = x => {
|
||||
var f = parseFloat(x)
|
||||
export const toDecimal2 = (x) => {
|
||||
let f = parseFloat(x)
|
||||
if (isNaN(f)) {
|
||||
return 0
|
||||
}
|
||||
f = f + ''
|
||||
let index = f.lastIndexOf('.')
|
||||
f = `${f}`
|
||||
const index = f.lastIndexOf('.')
|
||||
if (index >= 0) {
|
||||
let decimal = f.substring(index + 1)
|
||||
const decimal = f.substring(index + 1)
|
||||
if (decimal.length == 1) {
|
||||
f = f.substring(0, index + 1) + decimal + '0'
|
||||
} else {
|
||||
f = `${f.substring(0, index + 1) + decimal}0`
|
||||
}
|
||||
else {
|
||||
f = f.substring(0, index + 1) + decimal.substring(0, 2)
|
||||
}
|
||||
}
|
||||
@@ -173,23 +176,24 @@ export const withBaseUrl = function(url) {
|
||||
* 去除前缀 //xxx.com 或者 http://xxx.com 或者 https://xxx.com
|
||||
* @param {string} url url路径
|
||||
*/
|
||||
export const breakupUrl = url => {
|
||||
export const breakupUrl = (url) => {
|
||||
return url?.replace(URL_REGEXP, '') ?? url
|
||||
}
|
||||
/**
|
||||
* 拼接前缀 http://xxx.com + /asdfsafdas/154531asdf465413.png
|
||||
* @param {string} url url路径
|
||||
*/
|
||||
export const jointUrl = url => {
|
||||
export const jointUrl = (url) => {
|
||||
return withBaseUrl(url) ? url : `${IMG_CND_Prefix}${url}`
|
||||
}
|
||||
|
||||
export const formatUrl = (url, suffix = '!w200') => {
|
||||
if (url) {
|
||||
url = url.includes(',') ? url.split(',')[0] : url
|
||||
return withBaseUrl(url) ? url + suffix : jointUrl(url) + suffix
|
||||
} else {
|
||||
return IMG_CND_Prefix + '/mall/no_img.png'
|
||||
url = url.includes(',') ? url.split(',')[0] : url
|
||||
return withBaseUrl(url) ? url + suffix : jointUrl(url) + suffix
|
||||
}
|
||||
else {
|
||||
return `${IMG_CND_Prefix}/mall/no_img.png`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,8 +206,9 @@ export const formatUrl = (url, suffix = '!w200') => {
|
||||
export const formatImgUrl = (url, suffix = '!w200') => {
|
||||
if (url) {
|
||||
return url.includes('http') ? url + suffix : IMG_CND_Prefix + url + suffix
|
||||
} else {
|
||||
return IMG_CND_Prefix + '/mall/no_img.png'
|
||||
}
|
||||
else {
|
||||
return `${IMG_CND_Prefix}/mall/no_img.png`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,11 +221,13 @@ export const formatImgUrl = (url, suffix = '!w200') => {
|
||||
*/
|
||||
export const isLabImage = (imgurl, rgb, suffix = '!w200') => {
|
||||
if (imgurl) {
|
||||
return { status: 1, value: IMG_CND_Prefix + '/' + imgurl + suffix }
|
||||
} else if (rgb.r != 0 || rgb.g != 0 || rgb.b != 0) {
|
||||
return { status: 1, value: `${IMG_CND_Prefix}/${imgurl}${suffix}` }
|
||||
}
|
||||
else if (rgb.r != 0 || rgb.g != 0 || rgb.b != 0) {
|
||||
return { status: 2, value: rgb }
|
||||
} else {
|
||||
return { status: 3, value: IMG_CND_Prefix + '/mall/no_img.png' }
|
||||
}
|
||||
else {
|
||||
return { status: 3, value: `${IMG_CND_Prefix}/mall/no_img.png` }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +240,8 @@ export const numberWithCommas = ({ number = 0, digit = 2 }) => {
|
||||
if (!isNaN(Number(number))) {
|
||||
// return parseFloat(number).toFixed(digit).replace(/^\B(?<!\.\d*)(?=(\d{3})+(?!\d))$/g, ",");
|
||||
return parseFloat(number).toLocaleString('zh', { minimumFractionDigits: digit })
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return 0.0
|
||||
}
|
||||
}
|
||||
@@ -241,19 +249,21 @@ export const numberWithCommas = ({ number = 0, digit = 2 }) => {
|
||||
// 计算数值大于指定值
|
||||
export const setPriceUnit = (num, cls) => {
|
||||
if (cls) {
|
||||
let res = formatMillionYuan(num, 1000)
|
||||
const res = formatMillionYuan(num, 1000)
|
||||
return {
|
||||
cls: res.million ? cls : '',
|
||||
num: res.num,
|
||||
}
|
||||
} else if (num > 100000000) {
|
||||
let res = formatMillionYuan(num, 100000000)
|
||||
}
|
||||
else if (num > 100000000) {
|
||||
const res = formatMillionYuan(num, 100000000)
|
||||
return {
|
||||
cls: res.million ? 's-e' : '',
|
||||
num: res.num,
|
||||
}
|
||||
} else {
|
||||
let res = formatMillionYuan(num)
|
||||
}
|
||||
else {
|
||||
const res = formatMillionYuan(num)
|
||||
return {
|
||||
cls: res.million ? 's-w' : '',
|
||||
num: res.num,
|
||||
@@ -261,30 +271,34 @@ export const setPriceUnit = (num, cls) => {
|
||||
}
|
||||
}
|
||||
|
||||
//不四舍五入, val:原数据,num:保留位数
|
||||
// 不四舍五入, val:原数据,num:保留位数
|
||||
const noScale = (val, num = 2) => {
|
||||
val = parseFloat(val)
|
||||
num = parseInt(num)
|
||||
const power = Math.pow(10, num)
|
||||
val = val * power + ''
|
||||
val = `${val * power}`
|
||||
val = val.split('.')[0]
|
||||
val = parseInt(val) / power
|
||||
return val
|
||||
}
|
||||
|
||||
//处理数据单位(自然数)
|
||||
export const dataUnit = val => {
|
||||
// 处理数据单位(自然数)
|
||||
export const dataUnit = (val) => {
|
||||
let newVal = ''
|
||||
val = parseFloat(val)
|
||||
if (val >= 100000000) {
|
||||
newVal = noScale(val / 100000000) + '亿'
|
||||
} else if (val >= 10000000) {
|
||||
newVal = noScale(val / 10000000) + 'kw'
|
||||
} else if (val >= 10000) {
|
||||
newVal = noScale(val / 10000) + 'w'
|
||||
} else if (val >= 1000) {
|
||||
newVal = noScale(val / 1000) + 'k'
|
||||
} else {
|
||||
newVal = `${noScale(val / 100000000)}亿`
|
||||
}
|
||||
else if (val >= 10000000) {
|
||||
newVal = `${noScale(val / 10000000)}kw`
|
||||
}
|
||||
else if (val >= 10000) {
|
||||
newVal = `${noScale(val / 10000)}w`
|
||||
}
|
||||
else if (val >= 1000) {
|
||||
newVal = `${noScale(val / 1000)}k`
|
||||
}
|
||||
else {
|
||||
newVal = val
|
||||
}
|
||||
return newVal
|
||||
|
||||
+84
-82
@@ -1,88 +1,90 @@
|
||||
const smallToBig = function (money) {
|
||||
// 将数字金额转换为大写金额
|
||||
var cnNums = new Array(
|
||||
'零',
|
||||
'壹',
|
||||
'贰',
|
||||
'叁',
|
||||
'肆',
|
||||
'伍',
|
||||
'陆',
|
||||
'柒',
|
||||
'捌',
|
||||
'玖'
|
||||
); //汉字的数字
|
||||
var cnIntRadice = new Array('', '拾', '佰', '仟'); //基本单位
|
||||
var cnIntUnits = new Array('', '万', '亿', '兆'); //对应整数部分扩展单位
|
||||
var cnDecUnits = new Array('角', '分', '毫', '厘'); //对应小数部分单位
|
||||
var cnInteger = '整'; //整数金额时后面跟的字符
|
||||
var cnIntLast = '元'; //整数完以后的单位
|
||||
//最大处理的数字
|
||||
var maxNum = 999999999999999.9999;
|
||||
var integerNum; //金额整数部分
|
||||
var decimalNum; //金额小数部分
|
||||
//输出的中文金额字符串
|
||||
var chineseStr = '';
|
||||
var parts; //分离金额后用的数组,预定义
|
||||
if (money == '') {
|
||||
return '';
|
||||
}
|
||||
const smallToBig = function(money) {
|
||||
// 将数字金额转换为大写金额
|
||||
const cnNums = [
|
||||
'零',
|
||||
'壹',
|
||||
'贰',
|
||||
'叁',
|
||||
'肆',
|
||||
'伍',
|
||||
'陆',
|
||||
'柒',
|
||||
'捌',
|
||||
'玖',
|
||||
] // 汉字的数字
|
||||
const cnIntRadice = ['', '拾', '佰', '仟'] // 基本单位
|
||||
const cnIntUnits = ['', '万', '亿', '兆'] // 对应整数部分扩展单位
|
||||
const cnDecUnits = ['角', '分', '毫', '厘'] // 对应小数部分单位
|
||||
const cnInteger = '整' // 整数金额时后面跟的字符
|
||||
const cnIntLast = '元' // 整数完以后的单位
|
||||
// 最大处理的数字
|
||||
const maxNum = 999999999999999.9999
|
||||
let integerNum // 金额整数部分
|
||||
let decimalNum // 金额小数部分
|
||||
// 输出的中文金额字符串
|
||||
let chineseStr = ''
|
||||
let parts // 分离金额后用的数组,预定义
|
||||
if (money == '') {
|
||||
return ''
|
||||
}
|
||||
|
||||
money = parseFloat(money);
|
||||
if (money >= maxNum) {
|
||||
//超出最大处理数字
|
||||
return '超出最大处理数字';
|
||||
}
|
||||
if (money == 0) {
|
||||
chineseStr = cnNums[0] + cnIntLast + cnInteger;
|
||||
return chineseStr;
|
||||
}
|
||||
money = parseFloat(money)
|
||||
if (money >= maxNum) {
|
||||
// 超出最大处理数字
|
||||
return '超出最大处理数字'
|
||||
}
|
||||
if (money == 0) {
|
||||
chineseStr = cnNums[0] + cnIntLast + cnInteger
|
||||
return chineseStr
|
||||
}
|
||||
|
||||
//四舍五入保留两位小数,转换为字符串
|
||||
money = Math.round(money * 100).toString();
|
||||
integerNum = money.substr(0, money.length - 2);
|
||||
decimalNum = money.substr(money.length - 2);
|
||||
// 四舍五入保留两位小数,转换为字符串
|
||||
money = Math.round(money * 100).toString()
|
||||
integerNum = money.substr(0, money.length - 2)
|
||||
decimalNum = money.substr(money.length - 2)
|
||||
|
||||
//获取整型部分转换
|
||||
if (parseInt(integerNum, 10) > 0) {
|
||||
var zeroCount = 0;
|
||||
var IntLen = integerNum.length;
|
||||
for (var i = 0; i < IntLen; i++) {
|
||||
var n = integerNum.substr(i, 1);
|
||||
var p = IntLen - i - 1;
|
||||
var q = p / 4;
|
||||
var m = p % 4;
|
||||
if (n == '0') {
|
||||
zeroCount++;
|
||||
} else {
|
||||
if (zeroCount > 0) {
|
||||
chineseStr += cnNums[0];
|
||||
}
|
||||
//归零
|
||||
zeroCount = 0;
|
||||
chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
|
||||
}
|
||||
if (m == 0 && zeroCount < 4) {
|
||||
chineseStr += cnIntUnits[q];
|
||||
}
|
||||
// 获取整型部分转换
|
||||
if (parseInt(integerNum, 10) > 0) {
|
||||
let zeroCount = 0
|
||||
const IntLen = integerNum.length
|
||||
for (var i = 0; i < IntLen; i++) {
|
||||
var n = integerNum.substr(i, 1)
|
||||
const p = IntLen - i - 1
|
||||
const q = p / 4
|
||||
const m = p % 4
|
||||
if (n == '0') {
|
||||
zeroCount++
|
||||
}
|
||||
else {
|
||||
if (zeroCount > 0) {
|
||||
chineseStr += cnNums[0]
|
||||
}
|
||||
chineseStr += cnIntLast;
|
||||
// 归零
|
||||
zeroCount = 0
|
||||
chineseStr += cnNums[parseInt(n)] + cnIntRadice[m]
|
||||
}
|
||||
if (m == 0 && zeroCount < 4) {
|
||||
chineseStr += cnIntUnits[q]
|
||||
}
|
||||
}
|
||||
//小数部分
|
||||
if (decimalNum != '') {
|
||||
var decLen = decimalNum.length;
|
||||
for (var i = 0; i < decLen; i++) {
|
||||
var n = decimalNum.substr(i, 1);
|
||||
if (n != '0') {
|
||||
chineseStr += cnNums[Number(n)] + cnDecUnits[i];
|
||||
}
|
||||
}
|
||||
chineseStr += cnIntLast
|
||||
}
|
||||
// 小数部分
|
||||
if (decimalNum != '') {
|
||||
const decLen = decimalNum.length
|
||||
for (var i = 0; i < decLen; i++) {
|
||||
var n = decimalNum.substr(i, 1)
|
||||
if (n != '0') {
|
||||
chineseStr += cnNums[Number(n)] + cnDecUnits[i]
|
||||
}
|
||||
}
|
||||
if (chineseStr == '') {
|
||||
chineseStr += cnNums[0] + cnIntLast + cnInteger;
|
||||
} else if (decimalNum == '' || /^0*$/.test(decimalNum)) {
|
||||
chineseStr += cnInteger;
|
||||
}
|
||||
return chineseStr;
|
||||
};
|
||||
export default smallToBig;
|
||||
}
|
||||
if (chineseStr == '') {
|
||||
chineseStr += cnNums[0] + cnIntLast + cnInteger
|
||||
}
|
||||
else if (decimalNum == '' || /^0*$/.test(decimalNum)) {
|
||||
chineseStr += cnInteger
|
||||
}
|
||||
return chineseStr
|
||||
}
|
||||
export default smallToBig
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
import Taro from "@tarojs/taro"
|
||||
import { BASE_URL } from "../constant"
|
||||
import Taro from '@tarojs/taro'
|
||||
import { BASE_URL } from '../constant'
|
||||
|
||||
//解析短码(主要用于右上角按钮分享)
|
||||
// 解析短码(主要用于右上角按钮分享)
|
||||
export const analysisShortCodeApi = (val) => {
|
||||
//解析短码
|
||||
Taro.request({
|
||||
url:BASE_URL+'/v1/mall/shortCode',
|
||||
method:"GET",
|
||||
data:{md5_key: val},
|
||||
success:(res) => {
|
||||
if(res.data.code == 0) {
|
||||
//绑定上下级
|
||||
bindParent(res.data.data.share_user_id)
|
||||
}
|
||||
}
|
||||
})
|
||||
// 解析短码
|
||||
Taro.request({
|
||||
url: `${BASE_URL}/v1/mall/shortCode`,
|
||||
method: 'GET',
|
||||
data: { md5_key: val },
|
||||
success: (res) => {
|
||||
if (res.data.code == 0) {
|
||||
// 绑定上下级
|
||||
bindParent(res.data.data.share_user_id)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
//绑定上下级
|
||||
// 绑定上下级
|
||||
const bindParent = (share_user_id) => {
|
||||
//绑定上下级
|
||||
Taro.request({
|
||||
url:BASE_URL+'/v1/mall/shortCode/bind',
|
||||
method:"POST",
|
||||
data:{share_user_id: share_user_id},
|
||||
success:(res) => {
|
||||
if(res.data.code == 0) {
|
||||
//绑定上下级
|
||||
}
|
||||
// 绑定上下级
|
||||
Taro.request({
|
||||
url: `${BASE_URL}/v1/mall/shortCode/bind`,
|
||||
method: 'POST',
|
||||
data: { share_user_id },
|
||||
success: (res) => {
|
||||
if (res.data.code == 0) {
|
||||
// 绑定上下级
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import Taro from "@tarojs/taro";
|
||||
|
||||
import Taro from '@tarojs/taro'
|
||||
|
||||
/**
|
||||
* 设置 系统 本地存储
|
||||
* @param {Object} systemInfo
|
||||
* @param {Object} systemInfo
|
||||
*/
|
||||
export const setSystem = (systemInfo) => {
|
||||
Taro.setStorageSync('system', JSON.stringify(systemInfo))
|
||||
@@ -19,7 +18,7 @@ export const getSystem = () => {
|
||||
|
||||
/**
|
||||
* 设置 小程序 本地存储
|
||||
* @param {Object} systemInfo
|
||||
* @param {Object} systemInfo
|
||||
*/
|
||||
export const setAccountInfo = (systemInfo) => {
|
||||
Taro.setStorageSync('accountInfo', JSON.stringify(systemInfo))
|
||||
@@ -35,9 +34,9 @@ export const getAccountInfo = () => {
|
||||
|
||||
/**
|
||||
* 设置 参数本地存储
|
||||
* @param {Object} info
|
||||
* @param {Object} info
|
||||
*/
|
||||
export const setParam = (info:Object) => {
|
||||
export const setParam = (info: Object) => {
|
||||
Taro.setStorageSync('params', JSON.stringify(info))
|
||||
}
|
||||
|
||||
@@ -46,5 +45,5 @@ export const setParam = (info:Object) => {
|
||||
*/
|
||||
export const getParam = () => {
|
||||
const res = Taro.getStorageSync('params') || null
|
||||
return res?JSON.parse(res):null
|
||||
return res ? JSON.parse(res) : null
|
||||
}
|
||||
|
||||
+41
-34
@@ -1,7 +1,7 @@
|
||||
import Taro from '@tarojs/taro'
|
||||
import type { SelectorQuery } from '@tarojs/taro/types/index'
|
||||
import { formatImgUrl } from './format'
|
||||
import { analysisShortCodeApi } from './shortCode'
|
||||
import Taro from '@tarojs/taro'
|
||||
import { SelectorQuery } from '@tarojs/taro/types/index'
|
||||
/**
|
||||
* 防抖
|
||||
* @param {*} fn
|
||||
@@ -11,7 +11,7 @@ import { SelectorQuery } from '@tarojs/taro/types/index'
|
||||
export const debounce = (fn, delay) => {
|
||||
let timer: any = null
|
||||
return (...param) => {
|
||||
if (timer) clearTimeout(timer)
|
||||
if (timer) { clearTimeout(timer) }
|
||||
timer = setTimeout(() => {
|
||||
fn(...param)
|
||||
}, delay)
|
||||
@@ -27,7 +27,7 @@ export const debounce = (fn, delay) => {
|
||||
export const throttle = (fn, delay) => {
|
||||
let pre = 0
|
||||
return (...params) => {
|
||||
let now = new Date().getTime()
|
||||
const now = new Date().getTime()
|
||||
if (now - pre > delay) {
|
||||
fn(...params)
|
||||
pre = now
|
||||
@@ -42,15 +42,16 @@ export const throttle = (fn, delay) => {
|
||||
* @returns
|
||||
*/
|
||||
export const getFilterData = (val = {}, arr: string[] = []) => {
|
||||
let res = {}
|
||||
for (let key in val) {
|
||||
const res = {}
|
||||
for (const key in val) {
|
||||
// undefined == null output: true
|
||||
if (val[key] != null && val[key] !== '' && !arr.includes(key)) {
|
||||
if (typeof val[key] == 'number') {
|
||||
if (!isNaN(val[key])) {
|
||||
if (!Number.isNaN(val[key])) {
|
||||
res[key] = val[key]
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
res[key] = val[key]
|
||||
}
|
||||
}
|
||||
@@ -62,26 +63,28 @@ export const getFilterData = (val = {}, arr: string[] = []) => {
|
||||
* @param {*} object
|
||||
* @returns
|
||||
*/
|
||||
export const copyObject = object => {
|
||||
export const copyObject = (object) => {
|
||||
if (object.constructor == Object) {
|
||||
let keys = Object.keys(object)
|
||||
let newObject = {}
|
||||
keys.map(key => {
|
||||
const keys = Object.keys(object)
|
||||
const newObject = {}
|
||||
keys.forEach((key) => {
|
||||
newObject[key] = copyObject(object[key])
|
||||
})
|
||||
return newObject
|
||||
} else if (object.constructor == Array) {
|
||||
return object.map(item => {
|
||||
}
|
||||
else if (object.constructor == Array) {
|
||||
return object.map((item) => {
|
||||
return copyObject(item)
|
||||
})
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return object
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} suffix
|
||||
*
|
||||
* @param {*} suffix
|
||||
* !w80
|
||||
!w100
|
||||
!w160
|
||||
@@ -99,35 +102,38 @@ interface DataLoadingStatus {
|
||||
total: number
|
||||
status: boolean
|
||||
}
|
||||
//获取数据加载状态 //0:数据从无到有加载数据,1,没有任何数据, 2:下拉加载,3:下拉没有数据
|
||||
// 获取数据加载状态 //0:数据从无到有加载数据,1,没有任何数据, 2:下拉加载,3:下拉没有数据
|
||||
export const dataLoadingStatus = ({ list = [], total = 0, status = false }: DataLoadingStatus) => {
|
||||
console.log('list & status',list, status);
|
||||
console.log('list & status', list, status)
|
||||
// 类型校验
|
||||
if (Object.prototype.toString.call(list) !== '[object Array]') {
|
||||
list = []
|
||||
}
|
||||
if (list.length == 0 && status) {
|
||||
return 0
|
||||
} else if (list.length == 0 && !status) {
|
||||
}
|
||||
else if (list.length == 0 && !status) {
|
||||
return 1
|
||||
} else if (list.length < total) {
|
||||
}
|
||||
else if (list.length < total) {
|
||||
return 2
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return 3
|
||||
}
|
||||
}
|
||||
|
||||
function delay(delayTime = 25): Promise<null> {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
// @ts-ignore
|
||||
// @ts-expect-error no error
|
||||
resolve()
|
||||
}, delayTime)
|
||||
})
|
||||
}
|
||||
|
||||
export function delayQuerySelector(selectorStr: string, delayTime = 500): Promise<any[]> {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
const selector: SelectorQuery = Taro.createSelectorQuery()
|
||||
delay(delayTime).then(() => {
|
||||
selector
|
||||
@@ -140,28 +146,29 @@ export function delayQuerySelector(selectorStr: string, delayTime = 500): Promis
|
||||
})
|
||||
}
|
||||
|
||||
//全局分享监听
|
||||
// 全局分享监听
|
||||
export const shareShop = () => {
|
||||
const page = Taro.getCurrentInstance().page
|
||||
//当有分享参数时,绑定上下级
|
||||
// 当有分享参数时,绑定上下级
|
||||
if (page && page.options?.share) {
|
||||
analysisShortCodeApi(page.options.share)
|
||||
}
|
||||
if (page && page.onShareAppMessage) {
|
||||
page.onShareAppMessage = res => {
|
||||
page.onShareAppMessage = (res) => {
|
||||
let path = ''
|
||||
let title = ''
|
||||
let imageUrl = ''
|
||||
let sortCode = Taro.getStorageSync('sort_code') ? JSON.parse(Taro.getStorageSync('sort_code')) : ''
|
||||
let pageInfo: any = page
|
||||
//商品详情分享
|
||||
const sortCode = Taro.getStorageSync('sort_code') ? JSON.parse(Taro.getStorageSync('sort_code')) : ''
|
||||
const pageInfo: any = page
|
||||
// 商品详情分享
|
||||
if (pageInfo.route === 'pages/details/index') {
|
||||
path = `/pages/details/index?share=${sortCode.shareShortDetail.code}`
|
||||
title = sortCode.shareShortDetail.title
|
||||
imageUrl = sortCode.shareShortDetail.img
|
||||
} else {
|
||||
path =
|
||||
pageInfo.route === 'pages/user/index'
|
||||
}
|
||||
else {
|
||||
path
|
||||
= pageInfo.route === 'pages/user/index'
|
||||
? `/pages/user/index?share=${sortCode.shareShortPage.code}`
|
||||
: `/pages/index/index?share=${sortCode.shareShortPage.code}`
|
||||
title = sortCode.shareShortPage.title
|
||||
|
||||
Reference in New Issue
Block a user