支持 block="6" 来指定色块数量

This commit is contained in:
陆柯 2020-05-11 07:52:47 +08:00
parent adc6944155
commit 1ec8c2c600
2 changed files with 26 additions and 7 deletions

View File

@ -9,12 +9,16 @@ export default {
type: { type: {
type: String, type: String,
default: 'hex' default: 'hex'
},
block: {
type: String,
default: ''
} }
}, },
data() { return { data() { return {
}}, }},
methods: { methods: {
num2hex(value){ // num num2hex(value){ // todo: num
if (value) { if (value) {
switch (typeof value){ switch (typeof value){
case 'number': value = value.toString(16); break; case 'number': value = value.toString(16); break;
@ -26,7 +30,15 @@ export default {
}, },
shrinkHex(hex){ shrinkHex(hex){
if (/^(0x)?[\dA-F]+$/i.test(hex)){ if (/^(0x)?[\dA-F]+$/i.test(hex)){
return hex.replace(/^0x/, '').replace(/^(\w{18})\w*(\w{18})$/, '$1$2') hex = hex.replace(/^0x/, '')
let length
switch(this.block){
case '2': return hex.replace(/^(\w{6})\w*(\w{6})$/, '$1$2')
case '4': return hex.replace(/^(\w{12})\w*(\w{12})$/, '$1$2')
case '6': return hex.replace(/^(\w{18})\w*(\w{18})$/, '$1$2')
case '8': return hex.replace(/^(\w{24})\w*(\w{24})$/, '$1$2')
default: return hex
}
} }
return '' return ''
}, },
@ -49,6 +61,13 @@ export default {
// let fullLength = len + (4-(rest?rest:4)) // let fullLength = len + (4-(rest?rest:4))
// address = address.padEnd(fullLength, 'A') // b64 '00'A. // address = address.padEnd(fullLength, 'A') // b64 '00'A.
let colorArray = address.match(/[0-9A-Za-z\-_]{4}/g) let colorArray = address.match(/[0-9A-Za-z\-_]{4}/g)
switch(this.block){
case "2": colorArray.splice(1, colorArray.length-2)
case "4": colorArray.splice(2, colorArray.length-4)
case "6": colorArray.splice(3, colorArray.length-6)
case "8": colorArray.splice(4, colorArray.length-8)
default:
}
return colorArray return colorArray
} }
return [] return []

View File

@ -3,7 +3,7 @@ based on
https://ext.dcloud.net.cn/plugin?id=672 https://ext.dcloud.net.cn/plugin?id=672
https://github.com/steffenx/uniapp_popup https://github.com/steffenx/uniapp_popup
*数组形式传值 传值
*type: success warn info fail loadingstring默认info *type: success warn info fail loadingstring默认info
*content: 内容string *content: 内容string
*duration: 消失时间Number默认2000 *duration: 消失时间Number默认2000