|
|
@@ -1,462 +0,0 @@
|
|
|
-<template>
|
|
|
- <transition name="el-zoom-in-top" @after-leave="doDestroy">
|
|
|
- <div
|
|
|
- v-show="showPopper"
|
|
|
- class="el-color-dropdown app-color-dropdown"
|
|
|
- :style="{
|
|
|
- zIndex:zIndex
|
|
|
- }"
|
|
|
- >
|
|
|
- <div class="flex between app-color-header">
|
|
|
- <div class="app-color-tabs flex left">
|
|
|
- <div class="tab" :class="{'active button--primary1':tab===1 }" @click="toggelTab(1)">{{ $t('选色器.选择色号')}}</div>
|
|
|
- <template v-if="$store.getters.device !== 'mobile'">
|
|
|
- <div class="tab" v-if="imageUrl" :class="{'active button--primary1':tab===2 }" @click="toggelTab(2)">{{ $t('选色器.从预览图中选择')}}</div>
|
|
|
- <div class="tab" :class="{'active button--primary1':tab===3 }" @click="toggelTab(3)">{{ $t('选色器.指定图片选择')}}</div>
|
|
|
- </template>
|
|
|
- </div>
|
|
|
- <div class="close flex right line-30"><i class="el-icon-close" @click="showPopper = false" /></div>
|
|
|
- </div>
|
|
|
- <div v-if="showTips" class="app-color-dropdown-tips__title flex between">
|
|
|
- <div>
|
|
|
- <span class="fs-12">{{ $t('选色器.提示:白色、灰色、黑色等改色效果较差,请替换其他颜色') }}</span>
|
|
|
- <span class="fs-12" v-if="tab == 3">,{{$t('选区换料.请尽量保持浏览器缩放为100%')}},{{$t('选区换料.非100%可能会导致拾取不准确')}}。</span>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <div class="flex left top app-color-dropdown-hb">
|
|
|
- <template v-if="tab === 1 && showPopper">
|
|
|
-
|
|
|
- <div class="app-color-dropdown-tips">
|
|
|
- <div class="app-color-dropdown-tips__color">
|
|
|
- <div
|
|
|
- v-for="item in colorList"
|
|
|
- :key="item"
|
|
|
- class="app-color-dropdown-tips__item"
|
|
|
- :style="'background-color: '+item"
|
|
|
- @click="customInput = item;handleConfirm()"
|
|
|
- />
|
|
|
- </div>
|
|
|
-
|
|
|
- <span class="el-color-dropdown__value mar-top-10">
|
|
|
- <el-input
|
|
|
- v-model="customInput"
|
|
|
- :placeholder="$t('选色器.请输入hex色值,#号开头')"
|
|
|
- :validate-event="false"
|
|
|
- size="mini"
|
|
|
- @keyup.native.enter="handleConfirm"
|
|
|
- @blur="handleConfirm"
|
|
|
- />
|
|
|
- </span>
|
|
|
-
|
|
|
- <span class="el-color-dropdown__value mar-top-10 flex">
|
|
|
- <div class="c-fff">r:<el-input
|
|
|
- v-model="r"
|
|
|
- :validate-event="false"
|
|
|
- size="mini"
|
|
|
- maxlength="3"
|
|
|
- @input="(val)=>changeRGB(val,'r')"
|
|
|
- @keyup.native.enter="handleRGBConfirm"
|
|
|
- @blur="handleRGBConfirm"
|
|
|
- /></div>
|
|
|
- <div class="mar-left-10 c-fff">g: <el-input
|
|
|
- v-model="g"
|
|
|
- :validate-event="false"
|
|
|
- size="mini"
|
|
|
- maxlength="3"
|
|
|
- @input="(val)=>changeRGB(val,'g')"
|
|
|
- @keyup.native.enter="handleRGBConfirm"
|
|
|
- @blur="handleRGBConfirm"
|
|
|
- />
|
|
|
- </div>
|
|
|
- <div class="mar-left-10 c-fff">b:
|
|
|
- <el-input
|
|
|
- v-model="b"
|
|
|
- :validate-event="false"
|
|
|
- size="mini"
|
|
|
- maxlength="3"
|
|
|
- @input="(val)=>changeRGB(val,'b')"
|
|
|
- @keyup.native.enter="handleRGBConfirm"
|
|
|
- @blur="handleRGBConfirm"
|
|
|
- />
|
|
|
- </div>
|
|
|
- </span>
|
|
|
-
|
|
|
- <div class="app-color-dropdown-tips__color_last ">
|
|
|
- <div class="line-40 c-fff fs-14 mar-top-10">{{ $t('选色器.最近选择')}}</div>
|
|
|
-
|
|
|
- <div class="app-color-dropdown-tips__color" style="max-height: 60px; overflow-y: auto">
|
|
|
- <div class="app-color-dropdown-tips__item" v-for="item,index in colorPCList" :key="item+'_'+index" :style="'background:'+item " @click="customInput = item;handleConfirm()"></div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <div class="wrapper">
|
|
|
- <div class="el-color-dropdown__main-wrapper mar-top-5">
|
|
|
- <hue-slider ref="hue" :color="color" vertical style="float: right;" />
|
|
|
- <sv-panel ref="sl" :color="color" />
|
|
|
- </div>
|
|
|
- <alpha-slider v-if="showAlpha" ref="alpha" :color="color" />
|
|
|
- <predefine v-if="predefine" :color="color" :colors="predefine" />
|
|
|
-
|
|
|
- </div>
|
|
|
-
|
|
|
-
|
|
|
- </template>
|
|
|
-
|
|
|
- <template v-if="tab === 2 && showPopper">
|
|
|
- <canvasEyeDropper
|
|
|
- :image-url="imageUrl"
|
|
|
- v-model="customInput"
|
|
|
- @change="handleConfirm"
|
|
|
- :canvas-style="{
|
|
|
- width:680,
|
|
|
- height:400,
|
|
|
- }"
|
|
|
- />
|
|
|
- </template>
|
|
|
-
|
|
|
- <template v-if="tab === 3 && showPopper">
|
|
|
- <uploadEyeDropper
|
|
|
- :img.sync="fileUrl"
|
|
|
- v-model="customInput"
|
|
|
- @change="handleConfirm"
|
|
|
- />
|
|
|
- </template>
|
|
|
-
|
|
|
- </div>
|
|
|
- <div class="flex right el-color-dropdown__btns flex between">
|
|
|
- <div class="app-color-dropdown_active-color">
|
|
|
- <div >{{ $t('选色器.已选颜色')}}:<span v-if="customInput" :style="{background:customInput}"></span></div>
|
|
|
- </div>
|
|
|
- <div>
|
|
|
- <el-button
|
|
|
- size="mini"
|
|
|
-
|
|
|
- class="el-color-dropdown__link-btn"
|
|
|
- @click="showPopper = false"
|
|
|
- >
|
|
|
- {{ $t('通用.取消') }}
|
|
|
- </el-button>
|
|
|
- <el-button
|
|
|
- size="mini"
|
|
|
- class="el-color-dropdown__link-btn"
|
|
|
- @click="$emit('clear')"
|
|
|
- >
|
|
|
- {{ $t('公共组件.清空') }}
|
|
|
- </el-button>
|
|
|
- <el-button
|
|
|
- plain
|
|
|
- size="mini"
|
|
|
- class="el-color-dropdown__btn button--primary1"
|
|
|
- @click="confirmValue"
|
|
|
- >
|
|
|
- {{ $t('公共组件.确定') }}
|
|
|
- </el-button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </transition>
|
|
|
-</template>
|
|
|
-
|
|
|
-<script>
|
|
|
-import SvPanel from 'element-ui/packages/color-picker/src/components/sv-panel'
|
|
|
-import HueSlider from 'element-ui/packages/color-picker/src/components/hue-slider'
|
|
|
-import AlphaSlider from 'element-ui/packages/color-picker/src/components/alpha-slider'
|
|
|
-import Predefine from 'element-ui/packages/color-picker/src/components/predefine'
|
|
|
-import Popper from 'element-ui/src/utils/vue-popper'
|
|
|
-import Locale from 'element-ui/src/mixins/locale'
|
|
|
-import ElInput from 'element-ui/packages/input'
|
|
|
-import ElButton from 'element-ui/packages/button'
|
|
|
-import canvasEyeDropper from '@/views/customized/components/ColorPicker/canvasEyeDropper'
|
|
|
-import uploadEyeDropper from '@/views/customized/components/ColorPicker/uploadEyeDropper'
|
|
|
-import { get, set } from '@/utils/cookie'
|
|
|
-import popupManager from 'element-ui/lib/utils/popup/popup-manager'
|
|
|
-import Color from 'element-ui/packages/color-picker/src/color'
|
|
|
-import { rgb } from '@/utils/reg'
|
|
|
-export default {
|
|
|
- name: 'ColorPickerDropdown',
|
|
|
-
|
|
|
- components: {
|
|
|
- SvPanel,
|
|
|
- HueSlider,
|
|
|
- AlphaSlider,
|
|
|
- ElInput,
|
|
|
- canvasEyeDropper,
|
|
|
- uploadEyeDropper,
|
|
|
- ElButton,
|
|
|
- Predefine
|
|
|
- },
|
|
|
-
|
|
|
- mixins: [Popper, Locale],
|
|
|
-
|
|
|
- props: {
|
|
|
- color: {
|
|
|
- required: true
|
|
|
- },
|
|
|
- imageUrl:String,
|
|
|
- showAlpha: Boolean,
|
|
|
- predefine: Array,
|
|
|
- showTips:{
|
|
|
- type: Boolean,
|
|
|
- default: true
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- data() {
|
|
|
- return {
|
|
|
- customInput: '',
|
|
|
- colorList: [
|
|
|
- '#000000', '#aa0000', '#005500', '#aa5500', '#00aa00', '#aaaa00', '#00ff00', '#aaff00',
|
|
|
- '#00007f', '#aa007f', '#00557f', '#aa557f', '#00aa7f', '#aaaa7f', '#00ff7f', '#aaff7f',
|
|
|
- '#0000ff', '#aa00ff', '#0055ff', '#aa55ff', '#00aaff', '#aaaaff', '#00ffff', '#aaffff',
|
|
|
- '#550000', '#ff0000', '#555500', '#ff5500', '#55aa00', '#ffaa00', '#55ff00', '#ffff00',
|
|
|
- '#55007f', '#ff007f', '#55557f', '#ff557f', '#55aa7f', '#ffaa7f', '#55ff7f', '#ffff7f',
|
|
|
- '#5500ff', '#ff00ff', '#5555ff', '#ff55ff', '#55aaff', '#ffaaff', '#55ffff', '#ffffff'
|
|
|
- ],
|
|
|
- r:"",
|
|
|
- g:"",
|
|
|
- b:"",
|
|
|
- colorPCList:['#FFFFFF','#000000'],
|
|
|
- tab:1,
|
|
|
- fileUrl:"",
|
|
|
- zIndex:popupManager.nextZIndex()
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- computed: {
|
|
|
- currentColor() {
|
|
|
- const parent = this.$parent
|
|
|
- return !parent.value && !parent.showPanelColor ? '' : parent.color.value
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- watch: {
|
|
|
- showPopper(val) {
|
|
|
- if (val === true) {
|
|
|
- this.$emit('showPopper')
|
|
|
- this.tab = 1;
|
|
|
- this.getcolorList();
|
|
|
- this.$nextTick(() => {
|
|
|
-
|
|
|
- this.zIndex = popupManager.nextZIndex()
|
|
|
- const { sl, hue, alpha } = this.$refs
|
|
|
- sl && sl.update()
|
|
|
- hue && hue.update()
|
|
|
- alpha && alpha.update()
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- currentColor: {
|
|
|
- immediate: true,
|
|
|
- handler(val) {
|
|
|
- this.customInput = val
|
|
|
- this.HEXTotRGB()
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- mounted() {
|
|
|
- this.$parent.popperElm = this.popperElm = this.$el
|
|
|
- this.referenceElm = this.$parent.$el
|
|
|
- },
|
|
|
-
|
|
|
- methods: {
|
|
|
- toggelTab(tab){
|
|
|
- this.tab = tab
|
|
|
- },
|
|
|
- confirmValue() {
|
|
|
- this.$emit('pick')
|
|
|
- this.setcolorList()
|
|
|
- this.getcolorList();
|
|
|
- },
|
|
|
- handleConfirm() {
|
|
|
- this.color.fromString(this.customInput)
|
|
|
- this.HEXTotRGB();
|
|
|
-
|
|
|
- },
|
|
|
- changeRGB(value,type){
|
|
|
- if(!rgb.test(value)){
|
|
|
- let v = parseInt(value)
|
|
|
- v = isNaN(v) ? "" : v
|
|
|
- v = v > 255 ? 255 : ""
|
|
|
- this[type] = v
|
|
|
- }else{
|
|
|
- this[type] = parseInt(value)
|
|
|
- }
|
|
|
- },
|
|
|
- handleRGBConfirm(){
|
|
|
- console.log('a')
|
|
|
- console.log(this.b)
|
|
|
- console.log(typeof this.b)
|
|
|
-
|
|
|
- if(typeof this.r !== 'number' || typeof this.g !== 'number' || typeof this.b !== 'number'){
|
|
|
- return;
|
|
|
- }
|
|
|
- console.log('b')
|
|
|
- const currentValueColor = new Color({
|
|
|
- enableAlpha: false,
|
|
|
- format: 'hex'
|
|
|
- });
|
|
|
- currentValueColor.fromString(`rgb(${this.r},${this.g},${this.b})`);
|
|
|
- if(currentValueColor.value){
|
|
|
- this.customInput = currentValueColor.value
|
|
|
- this.color.fromString(this.customInput)
|
|
|
- }
|
|
|
- },
|
|
|
- HEXTotRGB(){
|
|
|
- if(!this.customInput){
|
|
|
-
|
|
|
- this.r = "";
|
|
|
- this.g = "";
|
|
|
- this.b = "";
|
|
|
- return;
|
|
|
- };
|
|
|
- const currentValueColor = new Color({
|
|
|
- enableAlpha: false,
|
|
|
- format: 'rgb'
|
|
|
- });
|
|
|
- currentValueColor.fromString(this.customInput);
|
|
|
- const {r,g,b} = this.displayedRgb(currentValueColor, false);
|
|
|
- this.r = r;
|
|
|
- this.g = g;
|
|
|
- this.b = b;
|
|
|
- },
|
|
|
- displayedRgb(color, showAlpha) {
|
|
|
- if (!(color instanceof Color)) {
|
|
|
- throw Error('color should be instance of Color Class');
|
|
|
- }
|
|
|
-
|
|
|
- return color.toRgb();
|
|
|
- },
|
|
|
- setcolorList(){
|
|
|
-
|
|
|
- let color = []
|
|
|
- try {
|
|
|
- color = JSON.parse(get('colorList'))
|
|
|
- } catch(e)
|
|
|
- {
|
|
|
- console.log(e)
|
|
|
- }
|
|
|
- if(color.includes(this.customInput)){
|
|
|
- return;
|
|
|
- }
|
|
|
- if(color.length >= 100){
|
|
|
- color.splice(0,1)
|
|
|
- }
|
|
|
- color.push(this.customInput)
|
|
|
- set('colorList',color)
|
|
|
- this.getcolorList()
|
|
|
-
|
|
|
- },
|
|
|
- getcolorList(){
|
|
|
- let arr = ['#FFFFFF','#000000']
|
|
|
- let color = []
|
|
|
- try {
|
|
|
-
|
|
|
- color = JSON.parse(get('colorList'))
|
|
|
- } catch(e)
|
|
|
- {
|
|
|
- console.log(e)
|
|
|
-
|
|
|
- }
|
|
|
- this.colorPCList = [...arr,...color].splice(0,56)
|
|
|
- },
|
|
|
- }
|
|
|
-}
|
|
|
-</script>
|
|
|
-
|
|
|
-<style lang="scss" scoped>
|
|
|
-</style>
|
|
|
-
|
|
|
-<style lang="scss">
|
|
|
-.app-color-dropdown {
|
|
|
- width: 710px;
|
|
|
- background: #212121;
|
|
|
- border:1px solid #212121;
|
|
|
- padding:0 ;
|
|
|
-
|
|
|
-
|
|
|
- .app-color-header {
|
|
|
- background: #383838;
|
|
|
- padding-right: 15px;
|
|
|
- margin-bottom: 10px;
|
|
|
- .app-color-tabs {
|
|
|
- .tab {
|
|
|
- color: #fff;
|
|
|
- font-size: 14px;
|
|
|
- padding: 10px 15px;
|
|
|
- cursor: pointer;
|
|
|
- &.active {
|
|
|
- border-bottom-left-radius: 0;
|
|
|
- border-bottom-right-radius: 0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- .app-color-dropdown-tips__title {
|
|
|
- color: #fff;
|
|
|
-
|
|
|
- padding: 0 10px;
|
|
|
- line-height: 30px;
|
|
|
- }
|
|
|
- .app-color-dropdown-hb {
|
|
|
- padding: 0 10px;
|
|
|
- height: 400px;
|
|
|
- }
|
|
|
- .app-color-dropdown-tips {
|
|
|
- width: 200px;
|
|
|
- margin-right: 10px;
|
|
|
- .app-color-dropdown-tips__color {
|
|
|
- display: flex;
|
|
|
- flex-wrap: wrap;
|
|
|
- .app-color-dropdown-tips__item {
|
|
|
- cursor: pointer;
|
|
|
- width: 20px;
|
|
|
- height: 20px;
|
|
|
- margin-right: 5px;
|
|
|
- margin-top:5px;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- .el-color-dropdown__value {
|
|
|
- width: 200px;
|
|
|
- }
|
|
|
- .el-color-dropdown__main-wrapper {
|
|
|
- width: 480px;
|
|
|
- height: 390px;
|
|
|
- .el-color-hue-slider {
|
|
|
- height: 390px !important;
|
|
|
- }
|
|
|
- .el-color-svpanel {
|
|
|
-
|
|
|
- width: 460px !important;
|
|
|
- height: 390px !important;
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- .el-color-dropdown__btns {
|
|
|
- padding: 5px 10px;
|
|
|
- .app-color-dropdown_active-color {
|
|
|
- color: #fff;
|
|
|
- font-size: 14px;
|
|
|
- span {
|
|
|
- padding: 0px 30px;
|
|
|
- }
|
|
|
- }
|
|
|
- border-top: 1px solid #333;
|
|
|
- .el-button {
|
|
|
- width: 80px;
|
|
|
- }
|
|
|
- }
|
|
|
- .close {
|
|
|
- color: #fff;
|
|
|
- height: 30px;
|
|
|
- .el-icon-close {
|
|
|
- cursor: pointer;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-</style>
|