Browse Source

Merge branch 'master' of ssh://code.fineres.com:7999/~dailer/fineui

es6
zsmj 2 years ago
parent
commit
d019d1d590
  1. 3
      bin/cli/worker/template/main_thread.helper.t
  2. 2
      package.json
  3. 34
      plugins/webpack-fui-worker-plugin/index.js
  4. 29
      plugins/webpack-fui-worker-plugin/worker-loader.js
  5. 6
      src/case/combo/iconcombo/combo.icon.js
  6. 245
      src/widget/time/time.combo.js

3
bin/cli/worker/template/main_thread.helper.t

@ -1,5 +1,7 @@
import { ${WorkerName}MainThreadWorker } from './main_thread/${workerName}_main_thread'; import { ${WorkerName}MainThreadWorker } from './main_thread/${workerName}_main_thread';
// 不需要一起打包的话则不需要引入这行 // 不需要一起打包的话则不需要引入这行
// FuiWorkerPlugin中的属性会同步到fui-worker中同时支持loader行内传入属性
// 根据实际需求传入inline返回格式 true -> blob urlfalse -> servicePath
import { workerUrl } from 'fui-worker!./worker_thread/${workerName}_worker_thread'; import { workerUrl } from 'fui-worker!./worker_thread/${workerName}_worker_thread';
export class ${WorkerName}WorkerHelper { export class ${WorkerName}WorkerHelper {
@ -23,6 +25,7 @@ export class ${WorkerName}WorkerHelper {
/** /**
* 格式化worker url比如补充一些环境信息到参数里 * 格式化worker url比如补充一些环境信息到参数里
* 可通过 #hash 将参数传入blob url
* @param url worker url * @param url worker url
*/ */
private urlFormatter(url: string) { private urlFormatter(url: string) {

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "fineui", "name": "fineui",
"version": "2.0.20220802151352", "version": "2.0.20220805101538",
"description": "fineui", "description": "fineui",
"main": "dist/fineui_without_conflict.min.js", "main": "dist/fineui_without_conflict.min.js",
"types": "dist/lib/index.d.ts", "types": "dist/lib/index.d.ts",

34
plugins/webpack-fui-worker-plugin/index.js

@ -5,6 +5,7 @@
const path = require('path'); const path = require('path');
const webpack = require('webpack'); const webpack = require('webpack');
const { WorkerPluginName } = require('./constants'); const { WorkerPluginName } = require('./constants');
const ModuleFilenameHelpers = require('webpack/lib/ModuleFilenameHelpers');
class FuiWorkerPlugin { class FuiWorkerPlugin {
constructor(options = {}) { constructor(options = {}) {
@ -39,6 +40,39 @@ class FuiWorkerPlugin {
// 动态添加 worker 的 worker-loader, 命名为 "fui-worker" // 动态添加 worker 的 worker-loader, 命名为 "fui-worker"
compiler.options.resolveLoader.alias['fui-worker'] = path.resolve(__dirname, './worker-loader.js'); compiler.options.resolveLoader.alias['fui-worker'] = path.resolve(__dirname, './worker-loader.js');
}); });
// 将FuiWorkerPlugin的参数传递给fui-worker loader
compiler.hooks.compilation.tap(WorkerPluginName, compilation => {
compilation.hooks.normalModuleLoader.tap(WorkerPluginName, (context, module) => {
// 仅提供给fui-worker
const fuiLoader = module.loaders.find(loader => loader.loader.indexOf('fui-worker') !== -1);
if (fuiLoader) {
const resource = module.resource;
if (!resource) return;
// fui-worker通过options读取
context.options = context.options || {};
const index = resource.indexOf('?');
if (ModuleFilenameHelpers.matchObject(
this.options,
index < 0 ? resource : resource.substr(0, index)
)) {
for (const key of Object.keys(this.options)) {
// 忽略关键属性
if (key === "include" || key === "exclude" || key === "test") {
continue;
}
context.options[key] = this.options[key];
}
}
}
})
})
} }
} }

29
plugins/webpack-fui-worker-plugin/worker-loader.js

@ -43,7 +43,7 @@ function loader() {
const entryFileName = `${FileNamePrefix}index`; const entryFileName = `${FileNamePrefix}index`;
// 获取传递给 loader 的 options // 获取传递给 loader 的 options
loaderUtils.getOptions(this) || {}; const options = Object.assign(loaderUtils.getOptions(this) || {}, this.options);
// 创建 childCompiler, 用于实现 worker 构建为独立 js 资源 // 创建 childCompiler, 用于实现 worker 构建为独立 js 资源
const childCompiler = this._compilation.createChildCompiler(WorkerLoaderName, { const childCompiler = this._compilation.createChildCompiler(WorkerLoaderName, {
@ -92,15 +92,24 @@ function loader() {
return callback(error); return callback(error);
} }
return callback( // 支持blob url形式
null, return options.inline
// 插入代码的转译和压缩由主构建配置的 babel/ts loader 处理, 不需要 worker-worker 来处理 ? callback(
// 添加 @ts-nocheck 避免 ts-check 报错 null,
`// @ts-nocheck // 插入代码的转译和压缩由主构建配置的 babel/ts loader 处理, 不需要 worker-worker 来处理
const servicePath = __webpack_public_path__ + ${JSON.stringify(entry)}; // 添加 @ts-nocheck 避免 ts-check 报错
export const workerUrl = servicePath; `// @ts-nocheck
` const blob = new Blob([${JSON.stringify(compilation.assets[entry].source())}]);
); export const workerUrl = window.URL.createObjectURL(blob);
`
)
: callback(
null,
`// @ts-nocheck
const servicePath = __webpack_public_path__ + ${JSON.stringify(entry)};
export const workerUrl = servicePath;
`
)
}); });
return; return;

6
src/case/combo/iconcombo/combo.icon.js

@ -20,7 +20,8 @@ BI.IconCombo = BI.inherit(BI.Widget, {
adjustXOffset: 0, adjustXOffset: 0,
adjustYOffset: 0, adjustYOffset: 0,
offsetStyle: "left", offsetStyle: "left",
chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE,
isShowDown: true
}); });
}, },
@ -42,7 +43,8 @@ BI.IconCombo = BI.inherit(BI.Widget, {
height: o.height, height: o.height,
iconWidth: o.iconWidth, iconWidth: o.iconWidth,
iconHeight: o.iconHeight, iconHeight: o.iconHeight,
value: o.value value: o.value,
isShowDown: o.isShowDown
}); });
this.popup = BI.createWidget(o.popup, { this.popup = BI.createWidget(o.popup, {
type: "bi.icon_combo_popup", type: "bi.icon_combo_popup",

245
src/widget/time/time.combo.js

@ -60,143 +60,136 @@
} }
}; };
return { return {
type: "bi.htape", type: "bi.horizontal_fill",
cls: "bi-border bi-border-radius",
columnSize: ["fill", this.constants.iconWidth],
height: opts.height - 2,
width: opts.width - 2,
items: [{ items: [{
type: "bi.absolute", el: {
items: [{ type: "bi.combo",
container: opts.container,
toggle: false,
isNeedAdjustHeight: opts.isNeedAdjustHeight,
isNeedAdjustWidth: opts.isNeedAdjustWidth,
el: { el: {
type: "bi.combo", type: "bi.time_trigger",
cls: "bi-border bi-border-radius", height: opts.height - 2,
container: opts.container, allowEdit: opts.allowEdit,
toggle: false, watermark: opts.watermark,
isNeedAdjustHeight: opts.isNeedAdjustHeight, format: opts.format,
isNeedAdjustWidth: opts.isNeedAdjustWidth, value: opts.value,
el: { ref: function (_ref) {
type: "bi.time_trigger", self.trigger = _ref;
height: opts.height - 2, },
allowEdit: opts.allowEdit, listeners: [{
watermark: opts.watermark, eventName: "EVENT_KEY_DOWN",
format: opts.format, action: function () {
value: opts.value, if (self.combo.isViewVisible()) {
ref: function (_ref) { self.combo.hideView();
self.trigger = _ref;
},
listeners: [{
eventName: "EVENT_KEY_DOWN",
action: function () {
if (self.combo.isViewVisible()) {
self.combo.hideView();
}
self.fireEvent(BI.TimeCombo.EVENT_KEY_DOWN, arguments);
}
}, {
eventName: "EVENT_STOP",
action: function () {
if (!self.combo.isViewVisible()) {
self.combo.showView();
}
}
}, {
eventName: "EVENT_FOCUS",
action: function () {
self.storeTriggerValue = self.trigger.getKey();
if (!self.combo.isViewVisible()) {
self.combo.showView();
}
self.fireEvent("EVENT_FOCUS");
}
}, {
eventName: "EVENT_BLUR",
action: function () {
self.fireEvent("EVENT_BLUR");
}
}, {
eventName: "EVENT_ERROR",
action: function () {
var date = BI.getDate();
self.storeValue = {
hour: date.getHours(),
minute: date.getMinutes(),
second: date.getSeconds()
};
self.fireEvent("EVENT_ERROR");
}
}, {
eventName: "EVENT_VALID",
action: function () {
self.fireEvent("EVENT_VALID");
} }
}, { self.fireEvent(BI.TimeCombo.EVENT_KEY_DOWN, arguments);
eventName: "EVENT_CHANGE", }
action: function () { }, {
self.fireEvent("EVENT_CHANGE"); eventName: "EVENT_STOP",
action: function () {
if (!self.combo.isViewVisible()) {
self.combo.showView();
} }
}, { }
eventName: "EVENT_CONFIRM", }, {
action: function () { eventName: "EVENT_FOCUS",
if (self.combo.isViewVisible()) { action: function () {
return; self.storeTriggerValue = self.trigger.getKey();
} if (!self.combo.isViewVisible()) {
var dateStore = self.storeTriggerValue; self.combo.showView();
var dateObj = self.trigger.getKey();
if (BI.isNotEmptyString(dateObj) && !BI.isEqual(dateObj, dateStore)) {
self.storeValue = self.trigger.getValue();
self.setValue(self.trigger.getValue());
} else if (BI.isEmptyString(dateObj)) {
self.storeValue = null;
self.trigger.setValue();
}
self.fireEvent("EVENT_CONFIRM");
} }
}] self.fireEvent("EVENT_FOCUS");
}, }
adjustLength: this.constants.comboAdjustHeight, }, {
popup: { eventName: "EVENT_BLUR",
el: popup,
width: opts.isNeedAdjustWidth ? opts.width : this.constants.popupWidth,
stopPropagation: false
},
hideChecker: function (e) {
return self.triggerBtn.element.find(e.target).length === 0;
},
listeners: [{
eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW,
action: function () { action: function () {
self.popup.setValue(self.storeValue); self.fireEvent("EVENT_BLUR");
self.fireEvent(BI.TimeCombo.EVENT_BEFORE_POPUPVIEW);
} }
}], }, {
ref: function (_ref) { eventName: "EVENT_ERROR",
self.combo = _ref; action: function () {
} var date = BI.getDate();
}, self.storeValue = {
top: 0, hour: date.getHours(),
left: 0, minute: date.getMinutes(),
right: 0, second: date.getSeconds()
bottom: 0 };
}, { self.fireEvent("EVENT_ERROR");
el: { }
type: "bi.icon_button", }, {
cls: "bi-trigger-icon-button time-font icon-size-16", eventName: "EVENT_VALID",
width: this.constants.iconWidth, action: function () {
height: opts.height, self.fireEvent("EVENT_VALID");
listeners: [{ }
eventName: BI.IconButton.EVENT_CHANGE, }, {
eventName: "EVENT_CHANGE",
action: function () {
self.fireEvent("EVENT_CHANGE");
}
}, {
eventName: "EVENT_CONFIRM",
action: function () { action: function () {
if (self.combo.isViewVisible()) { if (self.combo.isViewVisible()) {
// self.combo.hideView(); return;
} else {
self.combo.showView();
} }
var dateStore = self.storeTriggerValue;
var dateObj = self.trigger.getKey();
if (BI.isNotEmptyString(dateObj) && !BI.isEqual(dateObj, dateStore)) {
self.storeValue = self.trigger.getValue();
self.setValue(self.trigger.getValue());
} else if (BI.isEmptyString(dateObj)) {
self.storeValue = null;
self.trigger.setValue();
}
self.fireEvent("EVENT_CONFIRM");
} }
}], }]
ref: function (_ref) { },
self.triggerBtn = _ref; adjustLength: this.constants.comboAdjustHeight,
} popup: {
el: popup,
width: opts.isNeedAdjustWidth ? opts.width : this.constants.popupWidth,
stopPropagation: false
},
hideChecker: function (e) {
return self.triggerBtn.element.find(e.target).length === 0;
}, },
top: 0, listeners: [{
right: 0 eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW,
}] action: function () {
self.popup.setValue(self.storeValue);
self.fireEvent(BI.TimeCombo.EVENT_BEFORE_POPUPVIEW);
}
}],
ref: function (_ref) {
self.combo = _ref;
}
},
}, {
el: {
type: "bi.icon_button",
cls: "bi-trigger-icon-button time-font",
width: this.constants.iconWidth,
listeners: [{
eventName: BI.IconButton.EVENT_CHANGE,
action: function () {
if (self.combo.isViewVisible()) {
// self.combo.hideView();
} else {
self.combo.showView();
}
}
}],
ref: function (_ref) {
self.triggerBtn = _ref;
}
},
}] }]
}; };
}, },
@ -228,7 +221,7 @@
focus: function () { focus: function () {
this.trigger.focus(); this.trigger.focus();
}, },
blur: function () { blur: function () {
this.trigger.blur(); this.trigger.blur();
}, },

Loading…
Cancel
Save