cloud-web-corejs 1.1.0-dev.64 → 1.1.0-dev.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cloud-web-corejs",
3
3
  "private": false,
4
- "version": "1.1.0-dev.64",
4
+ "version": "1.1.0-dev.65",
5
5
  "scripts": {
6
6
  "build:ace-resources": "node build/build-ace-resources.js",
7
7
  "build:tinymce-resources": "node build/build-tinymce-resources.js",
@@ -158,6 +158,7 @@
158
158
  "src/components/cnPrint",
159
159
  "src/components/code-editor",
160
160
  "src/components/confirmDialog",
161
+ "src/components/messageBox",
161
162
  "src/components/errorMsg",
162
163
  "src/components/excelExport",
163
164
  "src/components/excelImport",
@@ -118,6 +118,10 @@ import baseAlert from "@base/components/baseAlert/index.js";
118
118
 
119
119
  Vue.use(baseAlert);
120
120
 
121
+ import MessageBox from "@base/components/messageBox/index.js";
122
+
123
+ Vue.use(MessageBox);
124
+
121
125
  import FormDialog from "@base/components/formDialog/index.js";
122
126
 
123
127
  Vue.use(FormDialog);
@@ -112,6 +112,10 @@ import baseAlert from "@base/components/baseAlert/index.js";
112
112
 
113
113
  Vue.use(baseAlert);
114
114
 
115
+ import MessageBox from "@base/components/messageBox/index.js";
116
+
117
+ Vue.use(MessageBox);
118
+
115
119
  import FormDialog from "@base/components/formDialog/index.js";
116
120
 
117
121
  Vue.use(FormDialog);
@@ -0,0 +1,68 @@
1
+ /**
2
+ * 表单脚本弹出消息框,底部按钮由调用方传入。
3
+ *
4
+ * this.$baseMessageBox({
5
+ * title: "请选择",
6
+ * content: "保存后是否继续提交?",
7
+ * buttons: [
8
+ * { code: "cancel", label: "取消", plain: true },
9
+ * { code: "save", label: "仅保存", type: "primary", plain: true },
10
+ * { code: "submit", label: "保存并提交", type: "primary" }
11
+ * ]
12
+ * }).then((code) => {
13
+ * // 点按钮 resolve code;点关闭或按 Esc resolve null
14
+ * });
15
+ *
16
+ * 按钮 onClick 的 this 是调用 $baseMessageBox 的组件。
17
+ * 返回 false,或返回的 Promise reject / resolve(false),弹窗保持打开。
18
+ */
19
+ const modules = {};
20
+ import vue from "vue";
21
+ import messageBox from "./index.vue";
22
+
23
+ const MessageBoxInstance = vue.extend(messageBox);
24
+ let currentMsg;
25
+ const initInstance = () => {
26
+ currentMsg = new MessageBoxInstance({ i18n: window.$vueRoot._i18n });
27
+ const msgBoxEl = currentMsg.$mount().$el;
28
+ document.body.appendChild(msgBoxEl);
29
+ };
30
+
31
+ function openMessageBox(option) {
32
+ const opts =
33
+ option && typeof option === "object"
34
+ ? option
35
+ : { content: option == null ? "" : String(option) };
36
+ if (!currentMsg) {
37
+ initInstance();
38
+ }
39
+ currentMsg.caller = this;
40
+ currentMsg.title = opts.title;
41
+ currentMsg.content = opts.content == null ? "" : String(opts.content);
42
+ currentMsg.buttons = Array.isArray(opts.buttons) ? opts.buttons : [];
43
+ currentMsg.showClose = opts.showClose !== false;
44
+ currentMsg.width = opts.width || "501px";
45
+ return currentMsg
46
+ .showMsgBox()
47
+ .then((val) => {
48
+ currentMsg.showWrap = false;
49
+ currentMsg.$destroy();
50
+ currentMsg.$el.remove();
51
+ currentMsg = null;
52
+ return Promise.resolve(val);
53
+ })
54
+ .catch((err) => {
55
+ currentMsg.showWrap = false;
56
+ currentMsg.$destroy();
57
+ currentMsg.$el.remove();
58
+ currentMsg = null;
59
+ return Promise.reject(err);
60
+ });
61
+ }
62
+
63
+ modules.install = function (Vue) {
64
+ Vue.prototype.$baseMessageBox = openMessageBox;
65
+ };
66
+ modules.openMessageBox = openMessageBox;
67
+
68
+ export default modules;
@@ -0,0 +1,77 @@
1
+ <template>
2
+ <div v-if="!$baseEventBus.isMobile">
3
+ <el-dialog
4
+ :title="displayTitle"
5
+ :visible.sync="showWrap"
6
+ v-if="showWrap"
7
+ :close-on-click-modal="false"
8
+ :width="width"
9
+ custom-class="dialog-style tips-dialog warning"
10
+ :append-to-body="true"
11
+ :show-close="showClose"
12
+ :before-close="handleBeforeClose"
13
+ v-el-drag-dialog
14
+ :destroy-on-close="true"
15
+ :modal="false"
16
+ @close="closeDialog"
17
+ >
18
+ <div class="cont" v-html="content"></div>
19
+ <span slot="footer" class="dialog-footer">
20
+ <el-button
21
+ v-for="(btn, index) in footerButtons"
22
+ :key="btn.code + '_' + index"
23
+ :type="btn.type"
24
+ :plain="btn.plain"
25
+ :loading="pendingIndex === index"
26
+ class="button-sty"
27
+ @click="handleButton(btn, index)"
28
+ >
29
+ <i v-if="btn.icon" :class="[btn.icon, 'el-icon']"></i>
30
+ {{ buttonLabel(btn) }}
31
+ </el-button>
32
+ </span>
33
+ </el-dialog>
34
+ </div>
35
+ <div v-else-if="showWrap">
36
+ <div class="pop-tipsBox" :style="'display: block;z-index:' + zIndex">
37
+ <div>
38
+ <i class="icon"></i>
39
+ <div class="cont">
40
+ <p class="name">
41
+ {{ displayTitle }}
42
+ </p>
43
+ <p class="txt" v-html="content"></p>
44
+ </div>
45
+ <div class="btns">
46
+ <el-button
47
+ v-for="(btn, index) in footerButtons"
48
+ :key="btn.code + '_' + index"
49
+ :type="btn.type"
50
+ :plain="btn.plain"
51
+ :loading="pendingIndex === index"
52
+ class="btn"
53
+ @click="handleButton(btn, index)"
54
+ >
55
+ {{ buttonLabel(btn) }}
56
+ </el-button>
57
+ </div>
58
+ </div>
59
+ </div>
60
+ </div>
61
+ </template>
62
+
63
+ <script>
64
+ import { mixins } from "./mixins";
65
+
66
+ export default {
67
+ mixins: [mixins],
68
+ };
69
+ </script>
70
+
71
+ <style lang="scss" scoped>
72
+ .pop-tipsBox {
73
+ .btns {
74
+ flex-wrap: wrap;
75
+ }
76
+ }
77
+ </style>
@@ -0,0 +1,155 @@
1
+ /**version-1.0*/
2
+ import PopupManager from "element-ui/src/utils/popup/popup-manager.js";
3
+
4
+ /**
5
+ * 把调用方按钮整理成渲染用的结构。
6
+ * 未传 buttons 时给出一个「确定」,code 为 confirm。
7
+ */
8
+ export function normalizeButtons(buttons) {
9
+ const source =
10
+ Array.isArray(buttons) && buttons.length
11
+ ? buttons
12
+ : [{ code: "confirm", label: "" }];
13
+ return source.map((btn, index) => {
14
+ const item = btn && typeof btn === "object" ? btn : {};
15
+ return {
16
+ code:
17
+ item.code != null && item.code !== "" ? item.code : `button_${index}`,
18
+ label: item.label != null ? item.label : "",
19
+ type: item.type || "primary",
20
+ plain: !!item.plain,
21
+ icon: item.icon || "",
22
+ onClick: typeof item.onClick === "function" ? item.onClick : null,
23
+ };
24
+ });
25
+ }
26
+
27
+ const tmixins = {
28
+ name: "baseMessageBox",
29
+ created() {
30
+ if (this.$baseEventBus && this.$baseEventBus.isMobile) {
31
+ this.zIndex = PopupManager.nextZIndex();
32
+ }
33
+ },
34
+ data() {
35
+ return {
36
+ title: null,
37
+ content: "",
38
+ buttons: [],
39
+ showClose: true,
40
+ width: "501px",
41
+ showWrap: false,
42
+ zIndex: null,
43
+ pendingIndex: -1,
44
+ settled: false,
45
+ caller: null,
46
+ };
47
+ },
48
+ computed: {
49
+ footerButtons() {
50
+ return normalizeButtons(this.buttons);
51
+ },
52
+ displayTitle() {
53
+ if (this.title == null) {
54
+ return this.$t1 ? this.$t1("提示") : "提示";
55
+ }
56
+ if (this.title === "") return "";
57
+ const text = String(this.title);
58
+ return this.$t1 ? this.$t1(text) : text;
59
+ },
60
+ },
61
+ beforeDestroy() {
62
+ this.removeEnterEvent();
63
+ },
64
+ methods: {
65
+ buttonLabel(btn) {
66
+ if (btn.label) {
67
+ return this.$t1 ? this.$t1(btn.label) : btn.label;
68
+ }
69
+ return this.$t1 ? this.$t1("确 定") : "确 定";
70
+ },
71
+ showMsgBox() {
72
+ const content = (this.content ?? "") + "";
73
+ this.content = content.replace(/(\r\n|\n|\r)/gm, "<br/>");
74
+ this.settled = false;
75
+ this.pendingIndex = -1;
76
+ this.showWrap = true;
77
+ this.removeEnterEvent();
78
+ this.addEnterEvent();
79
+ this.promise = new Promise((resolve, reject) => {
80
+ this.resolve = resolve;
81
+ this.reject = reject;
82
+ });
83
+ return this.promise;
84
+ },
85
+ settle(value) {
86
+ if (this.settled) return;
87
+ this.settled = true;
88
+ this.pendingIndex = -1;
89
+ this.removeEnterEvent();
90
+ this.showWrap = false;
91
+ if (this.resolve) this.resolve(value);
92
+ },
93
+ closeDialog() {
94
+ if (this.pendingIndex >= 0) return;
95
+ this.settle(null);
96
+ },
97
+ handleBeforeClose(done) {
98
+ if (this.pendingIndex >= 0 || this.settled) return;
99
+ done();
100
+ },
101
+ handleButton(btn, index) {
102
+ if (this.settled || this.pendingIndex >= 0) return;
103
+ if (!btn.onClick) {
104
+ this.settle(btn.code);
105
+ return;
106
+ }
107
+ this.pendingIndex = index;
108
+ let result;
109
+ try {
110
+ result = btn.onClick.call(this.caller);
111
+ } catch (error) {
112
+ this.pendingIndex = -1;
113
+ return;
114
+ }
115
+ if (result === false) {
116
+ this.pendingIndex = -1;
117
+ return;
118
+ }
119
+ Promise.resolve(result).then(
120
+ (value) => {
121
+ if (this.settled) return;
122
+ if (value === false) {
123
+ this.pendingIndex = -1;
124
+ return;
125
+ }
126
+ this.settle(btn.code);
127
+ },
128
+ () => {
129
+ if (!this.settled) this.pendingIndex = -1;
130
+ }
131
+ );
132
+ },
133
+ keyDown(e) {
134
+ if (this.$baseEventBus && this.$baseEventBus.isMobile) return;
135
+ if (e.keyCode !== 13 && e.keyCode !== 27) return;
136
+ e.stopPropagation();
137
+ if (e.keyCode === 27) {
138
+ this.closeDialog();
139
+ return;
140
+ }
141
+ const buttons = this.footerButtons;
142
+ if (!buttons.length) return;
143
+ const lastIndex = buttons.length - 1;
144
+ this.handleButton(buttons[lastIndex], lastIndex);
145
+ },
146
+ addEnterEvent() {
147
+ window.addEventListener("keydown", this.keyDown, true);
148
+ },
149
+ removeEnterEvent() {
150
+ window.removeEventListener("keydown", this.keyDown, true);
151
+ },
152
+ },
153
+ };
154
+
155
+ export const mixins = tmixins;
@@ -0,0 +1,92 @@
1
+ # 消息框自定义按钮
2
+
3
+ 详情弹框用 `openFormDialog` 打开。底部默认「确定」点下去会进 `confirm`,这里先做表单校验,通过后再用 `$baseMessageBox` 弹出消息框。底部按钮由调用方传入,点哪个按钮,Promise 就得到哪个按钮的 `code`。
4
+
5
+ `$baseConfirm`、`$baseAlert` 仍然只有固定的「取消 / 确定」。保存方法默认还会再弹一次「您确定要保存吗?」,这里把 `isConfirm` 设为 `false`,避免校验通过后又出现那个确认框。
6
+
7
+ ## 参数
8
+
9
+ | 参数 | 默认 | 说明 |
10
+ | --- | --- | --- |
11
+ | `title` | `提示` | 标题。传入的文字显示前走 `$t1`;不传时用 `$t1("提示")`。传空字符串则标题为空 |
12
+ | `content` | 空 | 正文,支持 HTML。换行会转成 `<br/>` |
13
+ | `buttons` | 一个「确定」 | 底部按钮,见下表。不传或空数组时,按钮 `code` 为 `confirm` |
14
+ | `showClose` | `true` | PC 是否显示右上角关闭。移动端没有这个关闭按钮 |
15
+ | `width` | `501px` | PC 弹窗宽度 |
16
+
17
+ ### buttons 每一项
18
+
19
+ | 字段 | 默认 | 说明 |
20
+ | --- | --- | --- |
21
+ | `code` | `button_序号` | 点击后 Promise 得到的值,用来区分按钮 |
22
+ | `label` | `确 定` | 按钮文字,显示前走 `$t1`。不传时用 `$t1("确 定")` |
23
+ | `type` | `primary` | Element 按钮类型,如 `primary`、`danger` |
24
+ | `plain` | `false` | 是否朴素按钮 |
25
+ | `icon` | 无 | 图标 class,如 `el-icon-check`。只在 PC 上显示 |
26
+ | `onClick` | 无 | 点击后、关闭前执行的函数。`this` 是调用 `$baseMessageBox` 的组件 |
27
+
28
+ ## 关闭结果
29
+
30
+ | 操作 | Promise 结果 |
31
+ | --- | --- |
32
+ | 点击某个按钮,且没有 `onClick` | 该按钮的 `code` |
33
+ | `onClick` 正常结束(含返回的 Promise resolve) | 该按钮的 `code` |
34
+ | 点击右上角关闭,或 PC 下按 Esc | `null` |
35
+ | PC 下按 Enter | 等同于点击最后一个按钮 |
36
+
37
+ `onClick` 返回 `false`、抛错、返回的 Promise reject,或 Promise resolve 出 `false` 时,弹窗保持打开,Promise 也不结束。这个按钮在请求过程中处于 loading,期间不能点其他按钮,也不能关闭。
38
+
39
+ 同一时间只打开一个消息框。上一个关掉之后再打开下一个。
40
+
41
+ ## 示例
42
+
43
+ 写在打开详情弹框的脚本里。`openFormDialog` 的默认「确定」不会自己校验;`confirm` 若不是返回 `false`,详情弹框会马上关闭。校验是异步的,所以这里固定返回 `false`,让详情弹框留着,再弹出消息框。
44
+
45
+ 校验不通过时消息框不会出现。消息框里点「取消」会关掉详情弹框,不保存。点消息框右上角或按 Esc 时 `code` 为 `null`,只关消息框,详情弹框仍打开。
46
+
47
+ 目标模板如果配了 `formConfig.actionButtons`,底部就不再是这个默认「确定」,`confirm` 也不会被调用。
48
+
49
+ ```javascript
50
+ let formRef = this.getFormRef();
51
+ formRef.openFormDialog({
52
+ formCode: "详情表单编码",
53
+ formConfig: {
54
+ dataId: dataId
55
+ },
56
+ confirm(dialogFormRef, dialog) {
57
+ dialogFormRef.validate((valid) => {
58
+ if (!valid) return;
59
+ dialogFormRef.$baseMessageBox({
60
+ title: "请选择",
61
+ content: "校验已通过,请选择后续操作",
62
+ buttons: [
63
+ { code: "cancel", label: "取消", plain: true, icon: "el-icon-close" },
64
+ { code: "save", label: "仅保存", type: "primary", plain: true, icon: "el-icon-check" },
65
+ { code: "submit", label: "保存并提交", type: "primary", icon: "el-icon-s-promotion" }
66
+ ]
67
+ }).then((code) => {
68
+ if (code === "cancel") {
69
+ dialog.close();
70
+ return;
71
+ }
72
+ if (code === "save") {
73
+ dialogFormRef.saveDefaultHandle({ config: { isConfirm: false } });
74
+ }
75
+ if (code === "submit") {
76
+ dialogFormRef.saveAndSubmitWfHandle({ config: { isConfirm: false } });
77
+ }
78
+ });
79
+ });
80
+ return false;
81
+ }
82
+ });
83
+ ```
84
+
85
+ ## 文件
86
+
87
+ | 文件 | 作用 |
88
+ | --- | --- |
89
+ | `src/components/messageBox/index.js` | 注册 `Vue.prototype.$baseMessageBox` |
90
+ | `src/components/messageBox/index.vue` | PC 弹窗与移动端 `.pop-tipsBox` |
91
+ | `src/components/messageBox/mixins.js` | 按钮整理、点击、关闭 |
92
+ | `src/app-bootstrap.js`、`src/app-bootstrap.sync.js` | 启动时 `Vue.use` |
@@ -290,8 +290,9 @@ export default {
290
290
  let sourceLabelField = this.sourceLabelField;
291
291
  let id = item[valueField] ?? null;
292
292
  let label = item[sourceLabelField] ?? null;
293
+ let oldValue = deepClone(this.fieldModel);
293
294
 
294
- //存储 ID(提交字段)
295
+ //存储 ID(提交字段),onChange 由 setValue 触发一次
295
296
  this.setValue(id);
296
297
  //存储展示名称(持久化到表单数据 + 输入框)
297
298
  this.setShowValue(label);
@@ -299,22 +300,32 @@ export default {
299
300
  //回填其他字段
300
301
  this.fillBackFields(item);
301
302
 
302
- //触发 onChange 自定义事件
303
- if (this.field.options.onChange) {
304
- let fn = new Function(
305
- "value",
306
- "oldValue",
307
- "item",
308
- this.field.options.onChange
309
- );
310
- fn.call(this, id, this.oldFieldValue, item);
311
- }
303
+ //选中项通过 onSelect 获取
304
+ this.fireOnSelect(id, oldValue, item);
312
305
  } finally {
313
306
  this.$nextTick(() => {
314
307
  this.isSelecting = false;
315
308
  });
316
309
  }
317
310
  },
311
+ /**
312
+ * 下拉选中事件。回填完成后触发,入参为选中项 item。
313
+ */
314
+ fireOnSelect(value, oldValue, item) {
315
+ if (!this.field.options.onSelect) return;
316
+ let tableParam = this.tableParam;
317
+ this.handleCustomEvent(
318
+ this.field.options.onSelect,
319
+ ["value", "oldValue", "item", "rowData", "rowIndex"],
320
+ [
321
+ value,
322
+ oldValue,
323
+ item,
324
+ tableParam ? tableParam.row : null,
325
+ tableParam ? tableParam.rowIndex : null,
326
+ ]
327
+ );
328
+ },
318
329
  /**
319
330
  * 清空:同时清除 ID 与名称
320
331
  */
@@ -0,0 +1,30 @@
1
+ <template>
2
+ <el-form-item label="onSelect" label-width="150px">
3
+ <a href="javascript:void(0);" class="a-link link-oneLind" @click="editEventHandler('onSelect', eventParams)">
4
+ <span>{{ optionModel.onSelect }}</span>
5
+ <i class="el-icon-edit"></i>
6
+ </a>
7
+ </el-form-item>
8
+ </template>
9
+
10
+ <script>
11
+ import i18n from "../../../../../../components/xform/utils/i18n";
12
+ import eventMixin from "../../../../../../components/xform/form-designer/setting-panel/property-editor/event-handler/eventMixin";
13
+
14
+ export default {
15
+ name: "onSelect-editor",
16
+ mixins: [i18n, eventMixin],
17
+ props: {
18
+ designer: Object,
19
+ selectedWidget: Object,
20
+ optionModel: Object,
21
+ },
22
+ data() {
23
+ return {
24
+ eventParams: ["dataId", "formCode", "value", "oldValue", "item", "rowData", "rowIndex"],
25
+ };
26
+ },
27
+ };
28
+ </script>
29
+
30
+ <style scoped></style>
@@ -252,6 +252,7 @@ const EVENT_PROPERTIES = {
252
252
  onClick: "onClick-editor",
253
253
  onInput: "onInput-editor",
254
254
  onChange: "onChange-editor",
255
+ onSelect: "onSelect-editor",
255
256
  onFocus: "onFocus-editor",
256
257
  onBlur: "onBlur-editor",
257
258
  onRemoteQuery: "onRemoteQuery-editor",
@@ -1096,6 +1096,7 @@ const autocompleteConfig = {
1096
1096
  onCreated: "",
1097
1097
  onMounted: "",
1098
1098
  onChange: "",
1099
+ onSelect: "",
1099
1100
  onFocus: "",
1100
1101
  onBlur: "",
1101
1102
  onInput: "",
@@ -73,7 +73,7 @@ export const constantRoutes = [
73
73
  },
74
74
  ],
75
75
  },*/
76
- ...(process.env.NODE_ENV === "development" ? [{
76
+ /* ...(process.env.NODE_ENV === "development" ? [{
77
77
  path: "",
78
78
  component: () => import("@/layout/index"),
79
79
  children: [
@@ -156,5 +156,5 @@ export const constantRoutes = [
156
156
  meta: { title: "产品系列", icon: "user" },
157
157
  },
158
158
  ],
159
- }] : []),
159
+ }] : []), */
160
160
  ];