支持 block="6" 来指定色块数量
This commit is contained in:
parent
adc6944155
commit
1ec8c2c600
@ -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 []
|
||||||
@ -67,22 +86,22 @@ export default {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<view class="sColorText">
|
<view class="sColorText">
|
||||||
<template v-if="type==='hex'">
|
<template v-if="type==='hex'">
|
||||||
<span class="sColorCode"
|
<span class="sColorCode"
|
||||||
v-for="(color,index) in hex2color(shrinkHex(colorText))"
|
v-for="(color,index) in hex2color(shrinkHex(colorText))"
|
||||||
:style="{background:`#${color}`}"
|
:style="{background:`#${color}`}"
|
||||||
:key="index">
|
:key="index">
|
||||||
{{color}}
|
{{color}}
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="type==='b64u'">
|
<template v-else-if="type==='b64u'">
|
||||||
<span class="sColorCode"
|
<span class="sColorCode"
|
||||||
v-for="(colorB64u,index) in address2colorB64u(colorText)"
|
v-for="(colorB64u,index) in address2colorB64u(colorText)"
|
||||||
:style="{background:`#${b64u2hex(colorB64u)}`}"
|
:style="{background:`#${b64u2hex(colorB64u)}`}"
|
||||||
:key="index">
|
:key="index">
|
||||||
{{colorB64u}}
|
{{colorB64u}}
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -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 loading(string),默认info
|
*type: success warn info fail loading(string),默认info
|
||||||
*content: 内容(string)
|
*content: 内容(string)
|
||||||
*duration: 消失时间(Number),默认2000
|
*duration: 消失时间(Number),默认2000
|
||||||
|
Loading…
Reference in New Issue
Block a user