vue 实现色板功能

news/2024/11/17 10:57:22/

效果:
在这里插入图片描述
动态添加颜色 随机色
在这里插入图片描述
代码:

<divclass="mt-10 firstTitle"v-show="pictureType != 'card' && pictureType != 'table' && pictureType !=  'inventory'"><i:class="[colorSystemShow ? 'el-icon-com-xiajiantou' : 'el-icon-com-youjiantou']"@click="colorSystem_before"class="c-pointer"></i><span class="ml-5">色板</span><span class="c-pointer pull-right" @click="colorConfig">配置</span><div v-show="colorSystemShow" class="mt-10 secondTitle colorSystem pl-5"><div v-for="itemOut in colorList" style="height:20px;" class="mt-5"><spanv-for="itemIn in itemOut.value":style="{background:itemIn}"style="display:inline-block;width:13.5px;height:20px;"></span></div></div></div>

组件:

<template><el-dialogtitle="色板配置":visible.sync="isColorConfigDialog"width="690px":close-on-click-modal="false":show-close="false"top="90px"><div class="mainDiv"><el-button class="ml-10" @click="add()" type="primary" size="mini" icon="el-icon-plus">新增色板</el-button><div v-for="(itemOut,i) in colorListCopy" style="height:20px;" class="mt-5"><span>{{i+1}}、</span><spanv-for="(itemIn,index) in itemOut.value":style="{background:itemIn}"style="display:inline-block;height:20px;"><el-inputstyle="width:30px;"v-model="aaa":value="itemIn"type="color"@change="colorChange($event,i,index)"></el-input></span><i class="el-icon-delete ml-10 mt-3 font16 c-pointer" @click="del(i)" title="删除"></i><!-- <span class="pull-right" style="margin-top:3px;"></span>--></div></div><span slot="footer" class="dialog-footer"><el-button size="mini" type="primary" @click="save">确 定</el-button><el-button size="mini" @click="exit">取 消</el-button></span></el-dialog>
</template>
<script>
export default {name: 'colorConfigDialog',props: ['isColorConfigDialog', 'colorList'],data() {return {aaa: '',colorListCopy: []}},mounted() {this.colorListCopy = JSON.parse(JSON.stringify(this.colorList))},methods: {save() {this.$emit('saveColorConfig', this.colorListCopy)this.$emit('closeColorConfigDialog')},exit() {this.$emit('closeColorConfigDialog')},colorChange(e, i, index) {this.aaa = ethis.colorListCopy[i].value[index] = ethis.$forceUpdate()},color16() {//十六进制颜色随机const r = Math.floor(Math.random() * 256)const g = Math.floor(Math.random() * 256)const b = Math.floor(Math.random() * 256)const color = `#${r.toString(16)}${g.toString(16)}${b.toString(16)}`return color},// 添加add() {let arr = []for (const item in this.colorListCopy[0].value) {let color = this.color16()arr.push(color)}let inParamsNew = [...this.colorListCopy]let obj = {key: this.colorListCopy.length,value: arr}inParamsNew.push(obj)this.colorListCopy = inParamsNew},del(index) {let inParamsNew = [...this.colorListCopy]if (inParamsNew.length < 2) {this.$message({type: 'warning',duration: '2000',message: '必须保留一行'})return}inParamsNew.splice(index, 1)this.colorListCopy = inParamsNew}}
}
</script><style lang="less" rel="stylesheet/less" scoped="true">
@import url('../../../common/less/variable.less');
.mainDiv {height: calc(100vh - 260px);overflow: auto;
}
/deep/input {border: 0; // 去除未选中状态边框outline: none; // 去除选中状态边框background-color: rgba(0, 0, 0, 0); // 透明背景
}
/deep/input[type='"color"']::-webkit-color-swatch-wrapper {padding: 0;
}
/deep/input[type='color']::-webkit-color-swatch {border: 0;
}
/deep/.el-input--mini .el-input__inner {height: 20px;
}
</style>

数据:

colorList: [{key: 1,value: ["#5B8FF9","#CDDDFD","#61DDAA","#CDF3E4","#65789B","#CED4DE","#F6BD16","#FCEBB9","#7262fd","#D3CEFD","#78D3F8","#D3EEF9","#9661BC","#DECFEA","#F6903D","#FFE0C7","#008685","#BBDEDE","#F08BB4","#FFE0ED"]},{key: 2,value: ["#FF6B3B","#626681","#FFC100","#9FB40F","#76523B","#DAD5B5","#0E8E89","#E19348","#F383A2","#247FEA","#2BCB95","#B1ABF4","#1D42C2","#1D9ED1","#D64BC0","#255634","#8C8C47","#8CDAE5","#8E283B","#791DC9"]},{key: 3,value: ["#025DF4","#DB6BCF","#2498D1","#BBBDE6","#4045B2","#21A97A","#FF745A","#007E99","#FFA8A8","#2391FF","#FFC328","#A0DC2C","#946DFF","#626681","#EB4185","#CD8150","#36BCCB","#327039","#803488","#83BC99"]},{key: 4,value: ["#FF4500","#1AAF8B","#406C85","#F6BD16","#B40F0F","#2FB8FC","#4435FF","#FF5CA2","#BBE800","#FE8A26","#946DFF","#6C3E00","#6193FF","#FF988E","#36BCCB","#004988","#FFCF9D","#CCDC8A","#8D00A1","#1CC25E"]}]

http://www.ppmy.cn/news/689314.html

相关文章

天锋w2019_天锋W2019上手,与三星W2019竟然完全一样,三星哭了!

原标题&#xff1a;天锋W2019上手&#xff0c;与三星W2019竟然完全一样&#xff0c;三星哭了&#xff01; 要说现在人们出门必需的物品是什么&#xff0c;相信大家的反应一定是&#xff1a;手机。是的&#xff0c;钱包可以不带&#xff0c;公交卡也可以不带&#xff0c;啥都能不…

三星w609 java_说说我的三星w609手机用着怎么样

说说我的三星w609手机用着怎么样 首先机器是双模双待&#xff0c;并且一张卡槽标明cdma&#xff0c;一张卡槽gsm/cdma. 外观不错&#xff0c;红色背壳&#xff0c;屏幕是硬屏.机器有点厚&#xff0c;不过看在双模双待的份上&#xff0c;还算不错. 系统是brew&#xff0c;支持ja…

CSS知识点汇总(四)

1. CSS优化方法 避免过度约束避免后代选择符避免链式选择符使用紧凑的语法避免不必要的命名空间避免不必要的重复最好使用表示语义的名字。避免&#xff01;important&#xff0c;可以选择其他选择器尽可能的精简规则&#xff0c;合并不同类里的重复规则 2. css sprite 是什么…

springboot+基于微信小程序音乐播放器的设计与实现 毕业设计-附源码271156

Springboot音乐播放小程序的设计与实现 摘 要 本文设计了一种基于微信小程序的音乐播放器&#xff0c;系统为人们提供了方便快捷、即用即搜的音乐搜索播放服务&#xff0c;包括音乐资讯、音乐库推荐、交流论坛、注册登录、最近播放列表功能等&#xff0c;用户不仅能够方便快捷地…

SSH的在线音乐下载网站-JAVA【数据库设计、源码、开题报告】

基于JSP在线音乐网站的设计与实现 学生姓名&#xff1a; 指导教师&#xff1a; 内容提要&#xff1a;本系统 是在eclipse 平台上运用JSP技术来实现的。其主要功能有&#xff1a;&#xff0c;首页&#xff0c;音乐下载界面&#xff0c;登陆界面&#xff0c;查看系统属性&am…

Nacos 1.4.x 服务发现源码阅读

客户端 关键属性 HostReactor Map<String, ScheduledFuture<?>> futureMap&#xff1a;缓存向服务端请求ServiceInfo的定时任务Map<String, ServiceInfo> serviceInfoMap&#xff1a;缓存从服务端获取的Service信息Map<String, Object> updatingMa…

2017年最全的电子杂志制作教程都在这里了

本文收集了2017年最全的电子杂志制作(www.yazine.com)教程供大家参考使用! 一、IEBOOK电子杂志制作

SSM+微信小程序网易云音乐设计与实现 毕业设计-附源码261620

基于SSM微信小程序的网易云音乐 摘 要 随着我国经济迅速发展&#xff0c;人们对手机的需求越来越大&#xff0c;各种手机软件也都在被广泛应用&#xff0c;但是对于手机进行数据信息管理&#xff0c;对于手机的各种软件也是备受用户的喜爱&#xff0c;微信小程序的网易云音乐系…