|
3 | 3 | <div class="label">
|
4 | 4 | <label>{{ item.data.label }}</label>
|
5 | 5 | <span v-if="item.data.required" class="item_require">*</span>
|
6 |
| - <el-tooltip v-if="item.data.tip" class="item" effect="dark" :content="item.data.tip" placement="top"> |
| 6 | + <el-tooltip |
| 7 | + v-if="item.data.tip" |
| 8 | + class="item" |
| 9 | + effect="dark" |
| 10 | + :content="item.data.tip" |
| 11 | + placement="top" |
| 12 | + > |
7 | 13 | <span class="tip iconfont icon-tishi"></span>
|
8 | 14 | </el-tooltip>
|
9 | 15 | </div>
|
10 | 16 | <div class="control">
|
11 |
| - <el-button style="width: 100%" @click="onStyleSet" :type="code?'primary':''">{{code?'已设置':'设置'}}</el-button> |
| 17 | + <el-button |
| 18 | + style="width: 100%" |
| 19 | + @click="onStyleSet" |
| 20 | + :type="code ? 'primary' : ''" |
| 21 | + >{{ code ? "已设置" : "设置" }}</el-button |
| 22 | + > |
12 | 23 | <custom-dialog ref="codeDialog" dialogclass="codeDialog" width="1000">
|
13 | 24 | <div class="custom_code">
|
14 |
| - <codemirror v-model="code" placeholder=".starfish-form-css{}" :style="{ height: '400px' }" :autofocus="true" :extensions="extensions" :indent-with-tab="true" :tab-size="2" /> |
| 25 | + <codemirror |
| 26 | + v-model="code" |
| 27 | + placeholder=".starfish-form-css{}" |
| 28 | + :style="{ height: '400px' }" |
| 29 | + :autofocus="true" |
| 30 | + :extensions="extensions" |
| 31 | + :indent-with-tab="true" |
| 32 | + :tab-size="2" |
| 33 | + /> |
15 | 34 | </div>
|
16 |
| - <el-footer class="my-Footer" style="text-align: center;"> |
| 35 | + <el-footer class="my-Footer" style="text-align: center"> |
17 | 36 | <el-button type="primary" @click="saveCssStyle">确定</el-button>
|
18 | 37 | <el-button @click="closeCodeDialog">关闭</el-button>
|
19 | 38 | </el-footer>
|
|
22 | 41 | </div>
|
23 | 42 | </template>
|
24 | 43 | <script lang="ts">
|
25 |
| - import { defineComponent, ref, getCurrentInstance } from "vue"; |
26 |
| - import { css } from "@codemirror/lang-css"; |
27 |
| - export default defineComponent({ |
28 |
| - ControlType: "FormStyle", // 必须与文件名匹配 |
29 |
| - isHide: true, |
30 |
| - props: { |
31 |
| - item: { |
32 |
| - type: Object, |
33 |
| - default: () => ({}), |
| 44 | +import { defineComponent, ref, getCurrentInstance } from "vue"; |
| 45 | +import { css } from "@codemirror/lang-css"; |
| 46 | +import { Codemirror } from "vue-codemirror"; |
| 47 | +export default defineComponent({ |
| 48 | + ControlType: "FormStyle", // 必须与文件名匹配 |
| 49 | + isHide: true, |
| 50 | + props: { |
| 51 | + item: { |
| 52 | + type: Object, |
| 53 | + default: () => ({}), |
| 54 | + }, |
| 55 | + data: { |
| 56 | + type: Object, |
| 57 | + default: () => ({}), |
| 58 | + }, |
| 59 | + controlItems: { |
| 60 | + type: Array, |
| 61 | + default: () => [], |
| 62 | + }, |
| 63 | + }, |
| 64 | + components: { |
| 65 | + Codemirror, |
| 66 | + }, |
| 67 | + setup(props) { |
| 68 | + const extensions = [css()]; |
| 69 | + const codeDialog = ref(); |
| 70 | + const code = ref(); |
| 71 | + const { proxy } = getCurrentInstance() as any; |
| 72 | + return { |
| 73 | + code, |
| 74 | + extensions, |
| 75 | + codeDialog, |
| 76 | + onStyleSet() { |
| 77 | + codeDialog.value.init("表单样式表", "icon-biaodan"); |
| 78 | + codeDialog.value.show(); |
34 | 79 | },
|
35 |
| - data: { |
36 |
| - type: Object, |
37 |
| - default: () => ({}), |
| 80 | + saveCssStyle() { |
| 81 | + props.data[props.item.data.fieldName] = code.value; |
| 82 | + proxy.extractCssClass(); |
| 83 | + proxy.insertCustomCssToHead(code.value); |
| 84 | + codeDialog.value.close(); |
38 | 85 | },
|
39 |
| - controlItems: { |
40 |
| - type: Array, |
41 |
| - default: () => [], |
| 86 | + closeCodeDialog() { |
| 87 | + codeDialog.value.close(); |
42 | 88 | },
|
43 |
| - }, |
44 |
| - setup(props) { |
45 |
| - const extensions = [css()]; |
46 |
| - const codeDialog = ref(); |
47 |
| - const code = ref(); |
48 |
| - const { proxy } = getCurrentInstance() as any; |
49 |
| - return { |
50 |
| - code, |
51 |
| - extensions, |
52 |
| - codeDialog, |
53 |
| - onStyleSet() { |
54 |
| - codeDialog.value.init("表单样式表", "icon-biaodan"); |
55 |
| - codeDialog.value.show(); |
56 |
| - }, |
57 |
| - saveCssStyle() { |
58 |
| - props.data[props.item.data.fieldName] = code.value; |
59 |
| - proxy.extractCssClass(); |
60 |
| - proxy.insertCustomCssToHead(code.value); |
61 |
| - codeDialog.value.close(); |
62 |
| - }, |
63 |
| - closeCodeDialog() { |
64 |
| - codeDialog.value.close(); |
65 |
| - }, |
66 |
| - extractCssClass() { |
67 |
| - const regExp = /\..*{/g; |
68 |
| - const result = code.value.match(regExp); |
69 |
| - const cssNameArray: any[] = []; |
70 |
| - if (!!result && result.length > 0) { |
71 |
| - result.forEach((rItem: any) => { |
72 |
| - const classArray = rItem.split(","); //切分逗号分割的多个class |
73 |
| - if (classArray.length > 0) { |
74 |
| - classArray.forEach((cItem: any) => { |
75 |
| - const caItem = cItem.trim(); |
76 |
| - if (caItem.indexOf(".", 1) !== -1) { |
77 |
| - //查找第二个.位置 |
78 |
| - const newClass = caItem.substring(caItem.indexOf(".") + 1, caItem.indexOf(".", 1)); //仅截取第一、二个.号之间的class |
79 |
| - if (newClass) { |
80 |
| - cssNameArray.push(newClass.trim()); |
81 |
| - } |
82 |
| - } else if (caItem.indexOf(" ") !== -1) { |
83 |
| - //查找第一个空格位置 |
84 |
| - const newClass = caItem.substring(caItem.indexOf(".") + 1, caItem.indexOf(" ")); //仅截取第一、二个.号之间的class |
85 |
| - if (newClass) { |
86 |
| - cssNameArray.push(newClass.trim()); |
87 |
| - } |
| 89 | + extractCssClass() { |
| 90 | + const regExp = /\..*{/g; |
| 91 | + const result = code.value.match(regExp); |
| 92 | + const cssNameArray: any[] = []; |
| 93 | + if (!!result && result.length > 0) { |
| 94 | + result.forEach((rItem: any) => { |
| 95 | + const classArray = rItem.split(","); //切分逗号分割的多个class |
| 96 | + if (classArray.length > 0) { |
| 97 | + classArray.forEach((cItem: any) => { |
| 98 | + const caItem = cItem.trim(); |
| 99 | + if (caItem.indexOf(".", 1) !== -1) { |
| 100 | + //查找第二个.位置 |
| 101 | + const newClass = caItem.substring( |
| 102 | + caItem.indexOf(".") + 1, |
| 103 | + caItem.indexOf(".", 1) |
| 104 | + ); //仅截取第一、二个.号之间的class |
| 105 | + if (newClass) { |
| 106 | + cssNameArray.push(newClass.trim()); |
| 107 | + } |
| 108 | + } else if (caItem.indexOf(" ") !== -1) { |
| 109 | + //查找第一个空格位置 |
| 110 | + const newClass = caItem.substring( |
| 111 | + caItem.indexOf(".") + 1, |
| 112 | + caItem.indexOf(" ") |
| 113 | + ); //仅截取第一、二个.号之间的class |
| 114 | + if (newClass) { |
| 115 | + cssNameArray.push(newClass.trim()); |
| 116 | + } |
| 117 | + } else { |
| 118 | + if (caItem.indexOf("{") !== -1) { |
| 119 | + //查找第一个{位置 |
| 120 | + const newClass = caItem.substring( |
| 121 | + caItem.indexOf(".") + 1, |
| 122 | + caItem.indexOf("{") |
| 123 | + ); |
| 124 | + cssNameArray.push(newClass.trim()); |
88 | 125 | } else {
|
89 |
| - if (caItem.indexOf("{") !== -1) { |
90 |
| - //查找第一个{位置 |
91 |
| - const newClass = caItem.substring(caItem.indexOf(".") + 1, caItem.indexOf("{")); |
92 |
| - cssNameArray.push(newClass.trim()); |
93 |
| - } else { |
94 |
| - const newClass = caItem.substring(caItem.indexOf(".") + 1); |
95 |
| - cssNameArray.push(newClass.trim()); |
96 |
| - } |
| 126 | + const newClass = caItem.substring(caItem.indexOf(".") + 1); |
| 127 | + cssNameArray.push(newClass.trim()); |
97 | 128 | }
|
98 |
| - }); |
99 |
| - } |
100 |
| - }); |
101 |
| - } |
102 |
| - props.controlItems.find((item: any) => { |
103 |
| - if (item.data.fieldName == "csslist") { |
104 |
| - item.data.itemConfig.items = []; |
105 |
| - cssNameArray.forEach((cssName: string, index: number) => { |
106 |
| - item.data.itemConfig.items.push({ |
107 |
| - label: cssName, |
108 |
| - value: cssName, |
109 |
| - select: false, |
110 |
| - id: index + 1, |
111 |
| - }); |
| 129 | + } |
112 | 130 | });
|
113 |
| - return item; |
114 | 131 | }
|
115 | 132 | });
|
116 |
| - }, |
117 |
| - insertCustomCssToHead(cssCode:string) { |
118 |
| - const head = document.getElementsByTagName("head")[0]; |
119 |
| - const oldStyle = document.getElementById("starfish-custom-css"); |
120 |
| - if (oldStyle) { |
121 |
| - head.removeChild(oldStyle); //先清除后插入!! |
122 |
| - } |
123 |
| - const newStyle: any = document.createElement("style"); |
124 |
| - newStyle.type = "text/css"; |
125 |
| - newStyle.rel = "stylesheet"; |
126 |
| - newStyle.id = "starfish-custom-css"; |
127 |
| - try { |
128 |
| - newStyle.appendChild(document.createTextNode(cssCode)); |
129 |
| - } catch (ex) { |
130 |
| - newStyle.styleSheet.cssText = cssCode; |
| 133 | + } |
| 134 | + props.controlItems.find((item: any) => { |
| 135 | + if (item.data.fieldName == "csslist") { |
| 136 | + item.data.itemConfig.items = []; |
| 137 | + cssNameArray.forEach((cssName: string, index: number) => { |
| 138 | + item.data.itemConfig.items.push({ |
| 139 | + label: cssName, |
| 140 | + value: cssName, |
| 141 | + select: false, |
| 142 | + id: index + 1, |
| 143 | + }); |
| 144 | + }); |
| 145 | + return item; |
131 | 146 | }
|
| 147 | + }); |
| 148 | + }, |
| 149 | + insertCustomCssToHead(cssCode: string) { |
| 150 | + const head = document.getElementsByTagName("head")[0]; |
| 151 | + const oldStyle = document.getElementById("starfish-custom-css"); |
| 152 | + if (oldStyle) { |
| 153 | + head.removeChild(oldStyle); //先清除后插入!! |
| 154 | + } |
| 155 | + const newStyle: any = document.createElement("style"); |
| 156 | + newStyle.type = "text/css"; |
| 157 | + newStyle.rel = "stylesheet"; |
| 158 | + newStyle.id = "starfish-custom-css"; |
| 159 | + try { |
| 160 | + newStyle.appendChild(document.createTextNode(cssCode)); |
| 161 | + } catch (ex) { |
| 162 | + newStyle.styleSheet.cssText = cssCode; |
| 163 | + } |
132 | 164 |
|
133 |
| - head.appendChild(newStyle); |
134 |
| - }, |
135 |
| - }; |
136 |
| - }, |
137 |
| - }); |
| 165 | + head.appendChild(newStyle); |
| 166 | + }, |
| 167 | + }; |
| 168 | + }, |
| 169 | +}); |
138 | 170 | </script>
|
0 commit comments