/** * 每次项目各自的通用方法定义 * 具体页面继承该View * 包括挂在在view上的接口管理的fetch,save */ import Magix from 'magix' import Chartx from './chartpark/index' import * as Service from './services/service' import Numeral from './public/numeral' import requester from 'dmp-new/services/requester' import { formatValue } from './format' import Base from './public/view' let GMessage = require('@./gallery/mx-gtip/message') let GTip = require('@./gallery/mx-gtip/index') const GLOBAL_GUIDE_WRAP_ID = 'globalGuideWrap' $(document).on('navslidend', () => { Chartx.resize() }) $(window).on('resize', () => { Chartx.resize() }) // type Omit = Pick>; // type Magix3Ext = Omit & { // extend( // props?: Magix3.TExtendPropertyDescriptor< // TProps & // Magix3.ViewPrototype & { // requester: typeof requester; // } // >, // statics?: TStatics // ): Magix3.View & TStatics; // }; const exportObj = Base.extend({ _confirm(viewOptions, dialogOptions) { return this.confirm(viewOptions, { ...dialogOptions, mask: true }) }, _confirmAsync(viewOptions, dialogOptions = {}) { return new Promise((resolve, reject) => { const _viewOptions = { ...viewOptions, enterCallback: () => { resolve(true) }, cancelCallback: () => { resolve(false) } } const _dialogOptions = { ...dialogOptions, mask: true } this.confirm(_viewOptions, _dialogOptions) }) }, _alert(title, content, enterCallback, dialogOptions) { if (Object.prototype.toString.call(title) === '[object Object]') { const viewOptions = title const dialogOptions = Object.assign( { mask: true }, content ?? {} ) return this.alert(viewOptions, dialogOptions) } else { return this.alert( title, content, enterCallback, Object.assign( { mask: true }, dialogOptions ?? {} ) ) } }, // getChartOptions(id) { // return $.extend(true, {}, Chartx.getOptions(id)) // }, getGlobalTheme() { return Chartx.getGlobalTheme() }, //确认某vframe加载完毕 waitVframeCreated(vframe) { return new Promise(resolve => { if (!vframe) { resolve(undefined) } else if (vframe.$cr == 1) { resolve(vframe) } else { vframe.on('created', e => { resolve(vframe) }) } }) } }).merge(Service, GMessage, GTip, { ctor() { const { Dayjs } = this.updater.get() // 兼容老的 Accounting Api const Accounting = { formatNumber: (number, precision = 0) => { let p = '' for (let i = 0; i < precision; i++) { p += '0' } return Numeral(number).format(`0,0.${p}`) } } const user = Magix.config('dmp-new.user') const all = Magix.config('dmp-new.all') this.updater.set({ user, all, Moment: Dayjs, Accounting, Numeral, formatValue }) // init request const me = this me.requester = {} //@ts-ignore for (let key in requester) { if (requester.hasOwnProperty(key)) { //@ts-ignore me.requester[key] = function (req: any, extra: any) { return requester[key](req, { ...extra, $view: me }) } } } }, // 加载引导浮层 showNewFunctionGuide() { this.removeNewFunctionGuide() this._guideItv = setTimeout(() => { if ($(`#${GLOBAL_GUIDE_WRAP_ID}`)[0]) { return } const rootId = Magix.config('rootId') const vf = Magix.Vframe.get(rootId) if (vf && vf.mountVframe) { $('body').append( `` ) vf.mountVframe(GLOBAL_GUIDE_WRAP_ID, 'dmp-new/views/new-function-guide') } }, 2000) }, // 销毁引导浮层 removeNewFunctionGuide() { clearTimeout(this._guideItv) const rootId = Magix.config('rootId') const vf = Magix.Vframe.get(rootId) if (vf && vf.unmountVframe) { vf.unmountVframe(GLOBAL_GUIDE_WRAP_ID) $(`#${GLOBAL_GUIDE_WRAP_ID}`).remove() } }, // 返回标签的4-1-1的selectTagOptionSet getStandardSelectTagOptionSet(tag) { const { all } = this.updater.get() const selectTagOptionSet = $.extend(true, {}, all.selectTagOptionSet_412) selectTagOptionSet.selectTagOptionSet[0].selectTagOptionSet[0].selectTagOptionSet[0] = tag return selectTagOptionSet }, // 获取全局 css 变量值 getCssGlobalVar(key, def) { let root = window.getComputedStyle(document.documentElement) let v = document.body.style.getPropertyValue(key) || root.getPropertyValue(key) if (!v) { return def || '' } else { return v.trim() } } }) // as Magix3Ext; exportObj.__esModule = true exportObj.default = exportObj export = exportObj