|
@@ -0,0 +1,351 @@
|
|
|
+<template>
|
|
|
+ <div v-dialogDrag v-if="isOpenDialog">
|
|
|
+ <div class="condition-dialog el-dialog">
|
|
|
+ <div class="header el-dialog__header">
|
|
|
+ <span>{{
|
|
|
+ $t("OnlineExcelPage.conditional_format") + "-" + chooseType
|
|
|
+ }}</span>
|
|
|
+ <i class="el-icon-close" @click="cancelHandle" />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="main">
|
|
|
+ <el-form
|
|
|
+ hide-required-asterisk
|
|
|
+ :model="ruleForm"
|
|
|
+ :rules="rules"
|
|
|
+ ref="ruleForm"
|
|
|
+ label-width="90px"
|
|
|
+ class="demo-ruleForm"
|
|
|
+ >
|
|
|
+ <div class="flex-align">
|
|
|
+ <el-form-item :label="chooseType" prop="pdzleft">
|
|
|
+ <el-input
|
|
|
+ @focus="momentRef = 'pdzleftRef'"
|
|
|
+ ref="pdzleftRef"
|
|
|
+ style="width: 100%"
|
|
|
+ v-model="ruleForm.pdzleft"
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <template v-if="chooseType == '介于'">
|
|
|
+ <span style="margin: 0 10px 22px">到</span>
|
|
|
+ <el-form-item
|
|
|
+ class="right-form-item"
|
|
|
+ label-width="0"
|
|
|
+ label=""
|
|
|
+ prop="pdzright"
|
|
|
+ >
|
|
|
+ <el-input
|
|
|
+ @focus="momentRef = 'pdzrightRef'"
|
|
|
+ ref="pdzrightRef"
|
|
|
+ style="width: 100%"
|
|
|
+ v-model="ruleForm.pdzright"
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </template>
|
|
|
+ <el-form-item label="设置为" prop="szw">
|
|
|
+ <el-select
|
|
|
+ style="width: 100%"
|
|
|
+ @change="changeColorSel"
|
|
|
+ v-model="ruleForm.szw"
|
|
|
+ placeholder="请设置样式"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="(color, colorIndex) in colorSelect"
|
|
|
+ :key="colorIndex"
|
|
|
+ :label="color.label"
|
|
|
+ :value="color.value"
|
|
|
+ ></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </div>
|
|
|
+ <div class="flex-align">
|
|
|
+ <el-form-item label="应用选区" prop="yyxq">
|
|
|
+ <el-input
|
|
|
+ @focus="momentRef = 'yyxqRef'"
|
|
|
+ ref="yyxqRef"
|
|
|
+ style="width: 100%"
|
|
|
+ v-model="ruleForm.yyxq"
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ v-if="ruleForm.szw === '自定义'"
|
|
|
+ label="填充色"
|
|
|
+ prop="bgColor"
|
|
|
+ >
|
|
|
+ <div class="flex-align">
|
|
|
+ <div class="flex-align">
|
|
|
+ <el-color-picker
|
|
|
+ v-model="ruleForm.bgColor"
|
|
|
+ show-alpha
|
|
|
+ ></el-color-picker>
|
|
|
+ <div class="flex-align">
|
|
|
+ <div
|
|
|
+ style="
|
|
|
+ width: 90px;
|
|
|
+ text-align: right;
|
|
|
+ padding-right: 12px;
|
|
|
+ "
|
|
|
+ >
|
|
|
+ 文本颜色
|
|
|
+ </div>
|
|
|
+ <el-color-picker
|
|
|
+ v-model="ruleForm.fontColor"
|
|
|
+ show-alpha
|
|
|
+ ></el-color-picker>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+ </div>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+ <section class="bot">
|
|
|
+ <el-button type="primary" plain @click="cancelHandle">{{
|
|
|
+ $t("ETable.Btn.cancel_btn")
|
|
|
+ }}</el-button>
|
|
|
+ <el-button type="primary" @click="saveHandle">{{
|
|
|
+ $t("ETableChildren.save_btn")
|
|
|
+ }}</el-button>
|
|
|
+ </section>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+export default {
|
|
|
+ props: {
|
|
|
+ chooseCell: {
|
|
|
+ type: Object,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ chooseCell: {
|
|
|
+ handler(nval) {
|
|
|
+ console.log(nval, this.momentRef);
|
|
|
+ if (nval && this.momentRef) {
|
|
|
+ if (this.momentRef == "yyxqRef") {
|
|
|
+ this.chooseArray = Array.isArray(nval) ? nval : [nval];
|
|
|
+ this.formatXq(this.chooseArray);
|
|
|
+ } else {
|
|
|
+ console.log(!Array.isArray(nval));
|
|
|
+ if (!Array.isArray(nval)) {
|
|
|
+ this.formatXq(
|
|
|
+ [nval],
|
|
|
+ this.momentRef === "pdzleftRef" ? "pdzleft" : "pdzright"
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deep: true,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ var validateValue = (rule, value, callback) => {
|
|
|
+ const regex1 = /^\$[A-Z]+\$[1-9][0-9]*$/;
|
|
|
+ if (value === "") {
|
|
|
+ callback(new Error("请输入数字或选择数值单元格"));
|
|
|
+ } else if (regex1.test(value) || Number.isFinite(+value)) {
|
|
|
+ callback();
|
|
|
+ } else {
|
|
|
+ callback(new Error("请输入数字或选择数值单元格"));
|
|
|
+ }
|
|
|
+ };
|
|
|
+ var validateYyxq = (rule, value, callback) => {
|
|
|
+ const regex1 = /^\$[A-Z]+\$[1-9][0-9]*$/;
|
|
|
+ const regex2 = /^\$[A-Z]+\$[1-9][0-9]*:\$[A-Z]+\$[1-9][0-9]*$/;
|
|
|
+ if (value === "") {
|
|
|
+ callback(new Error("请选择数值单元格"));
|
|
|
+ } else if (regex1.test(value) || regex2.test(value)) {
|
|
|
+ callback();
|
|
|
+ } else {
|
|
|
+ callback(new Error("单元格格式不正确"));
|
|
|
+ }
|
|
|
+ };
|
|
|
+ return {
|
|
|
+ chooseType: "",
|
|
|
+ isOpenDialog: false,
|
|
|
+ chooseArray: [],
|
|
|
+ colorSelect: [
|
|
|
+ {
|
|
|
+ label: "浅红色填充色深红色文本",
|
|
|
+ value: "rgb(254,67,101)-rba(252,157,154)", //前为文本颜色,后为填充色
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "黄填充色深黄色文本",
|
|
|
+ value: "rgb(255,255,224)-rba(255,215,0)",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "绿填充色深绿色文本",
|
|
|
+ value: "rgb(0,100,0)-rba(0,255,0)",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "浅红色填充",
|
|
|
+ value: "''-rba(252,157,154)",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "红色文本",
|
|
|
+ value: "rgb(255, 0, 0)-''",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "自定义格式...",
|
|
|
+ value: "自定义",
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ ruleForm: {
|
|
|
+ pdzleft: "",
|
|
|
+ pdzright: "",
|
|
|
+ szw: "rgb(254,67,101)-rba(252,157,154)",
|
|
|
+ fontColor: "rgb(254,67,101)",
|
|
|
+ bgColor: "rba(252,157,154)",
|
|
|
+ yyxq: "",
|
|
|
+ },
|
|
|
+ rules: {
|
|
|
+ pdzleft: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: "请输入数字或选择数值单元格",
|
|
|
+ trigger: ["blur", "change"],
|
|
|
+ },
|
|
|
+ { validator: validateValue, trigger: "blur" },
|
|
|
+ ],
|
|
|
+ pdzright: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: "请输入数字或选择数值单元格",
|
|
|
+ trigger: ["blur", "change"],
|
|
|
+ },
|
|
|
+ { validator: validateValue, trigger: "blur" },
|
|
|
+ ],
|
|
|
+ szw: [{ required: true, message: "请选择样式", trigger: "change" }],
|
|
|
+ yyxq: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: "请输入或选择应用选区",
|
|
|
+ trigger: ["blur", "change"],
|
|
|
+ },
|
|
|
+ { validator: validateYyxq, trigger: "blur" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ };
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ // 切换颜色选择
|
|
|
+ changeColorSel(val) {
|
|
|
+ const colorArr = val.split("-");
|
|
|
+ this.ruleForm.fontColor = val != "自定义" ? colorArr[0] : "";
|
|
|
+ this.ruleForm.bgColor = val != "自定义" ? colorArr[1] : "";
|
|
|
+ },
|
|
|
+ // 保存
|
|
|
+ saveHandle() {
|
|
|
+ this.momentRef = "";
|
|
|
+ this.$refs["ruleForm"].validate((valid) => {
|
|
|
+ if (valid) {
|
|
|
+ console.log(this.ruleForm);
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 打开弹框
|
|
|
+ openDialog(type, array) {
|
|
|
+ this.chooseType = type;
|
|
|
+ this.isOpenDialog = true;
|
|
|
+ this.chooseArray = array;
|
|
|
+ this.formatXq(this.chooseArray);
|
|
|
+ },
|
|
|
+ formatXq(array, key = "yyxq") {
|
|
|
+ console.log(array);
|
|
|
+ if (array.length < 2) {
|
|
|
+ this.ruleForm[key] = "$" + array[0].colIndex + "$" + array[0].rowIndex;
|
|
|
+ } else {
|
|
|
+ let str = "";
|
|
|
+ array.forEach((el, index) => {
|
|
|
+ if (index === 0 || index == array.length - 1) {
|
|
|
+ str +=
|
|
|
+ "$" +
|
|
|
+ array[index].colIndex +
|
|
|
+ "$" +
|
|
|
+ array[index].rowIndex +
|
|
|
+ (index === 0 ? ":" : "");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.ruleForm[key] = str;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ cancelHandle() {
|
|
|
+ this.momentRef = "";
|
|
|
+ this.isOpenDialog = false;
|
|
|
+ },
|
|
|
+ handleClickOutside(event) {
|
|
|
+ let _this = this;
|
|
|
+ console.log(_this);
|
|
|
+ // 检查点击是否发生在el-input外
|
|
|
+ if (
|
|
|
+ this.$refs[_this.momentRef] &&
|
|
|
+ !this.$refs.pdzleftRef.$el.contains(event.target)
|
|
|
+ ) {
|
|
|
+ // 如果是,则将焦点设置到当前el-input
|
|
|
+ this.$refs[_this.momentRef].focus();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ // 监听全局点击事件
|
|
|
+ document.addEventListener("click", this.handleClickOutside);
|
|
|
+ },
|
|
|
+ beforeDestroy() {
|
|
|
+ // 组件销毁前移除监听
|
|
|
+ document.removeEventListener("click", this.handleClickOutside);
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style lang="scss" scoped>
|
|
|
+@import "~@/styles/theme-vars.scss";
|
|
|
+.condition-dialog {
|
|
|
+ background: #fff;
|
|
|
+ position: fixed;
|
|
|
+ top: 20%;
|
|
|
+ left: 50%;
|
|
|
+ width: 750px;
|
|
|
+ border-radius: 2px;
|
|
|
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
|
|
|
+ z-index: 9999;
|
|
|
+ .header {
|
|
|
+ font-size: 16px;
|
|
|
+ background: $theme-color;
|
|
|
+ color: #fff;
|
|
|
+ padding: 15px;
|
|
|
+ display: flex;
|
|
|
+ align-content: center;
|
|
|
+ justify-content: space-between;
|
|
|
+ .el-icon-close {
|
|
|
+ font-size: 20px;
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .main {
|
|
|
+ padding: 20px;
|
|
|
+ max-height: calc(100vh - 350px);
|
|
|
+ min-height: 300px;
|
|
|
+ overflow-y: auto;
|
|
|
+ .main-top {
|
|
|
+ margin-bottom: 20px;
|
|
|
+ .right-form-item {
|
|
|
+ .el-form-item__error {
|
|
|
+ padding-left: 20px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .bot {
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
+ margin: 30px 0;
|
|
|
+ }
|
|
|
+ .flex-align {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|