zn-components 0.0.2 → 0.0.5

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.
@@ -1,3 +1,27 @@
1
1
  /*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
2
2
 
3
3
  /*! xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
4
+
5
+ /**
6
+ * @license
7
+ * Lodash <https://lodash.com/>
8
+ * Copyright JS Foundation and other contributors <https://js.foundation/>
9
+ * Released under MIT license <https://lodash.com/license>
10
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
11
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
12
+ */
13
+
14
+ /**
15
+ * Checks if an event is supported in the current execution environment.
16
+ *
17
+ * NOTE: This will not work correctly for non-generic events such as `change`,
18
+ * `reset`, `load`, `error`, and `select`.
19
+ *
20
+ * Borrows from Modernizr.
21
+ *
22
+ * @param {string} eventNameSuffix Event name, e.g. "click".
23
+ * @param {?boolean} capture Check if the capture phase is supported.
24
+ * @return {boolean} True if the event is supported.
25
+ * @internal
26
+ * @license Modernizr 3.0.0pre (Custom Build) | MIT
27
+ */
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "zn-components",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "description": "zn-components",
5
- "main": "index.js",
5
+ "homepage": "https://u.zznccc.cn",
6
+ "main": "dist/zn-ui.min.js",
6
7
  "files": [
7
- "dist",
8
- "src"
8
+ "dist"
9
9
  ],
10
10
  "peerDependencies": {
11
11
  "vue": "^2.0.0"
@@ -1 +0,0 @@
1
- (("undefined"!=typeof self?self:this).webpackJsonpZnUI=("undefined"!=typeof self?self:this).webpackJsonpZnUI||[]).push([[0],{144:function(e,t,n){"use strict";n.r(t);var i=function render(){var e=this,t=e._self._c;return t("transition",{attrs:{name:"viewer-fade"}},[t("div",{ref:"el-image-viewer__wrapper",staticClass:"el-image-viewer__wrapper",style:{"z-index":e.viewerZIndex},attrs:{tabindex:"-1"}},[t("div",{staticClass:"el-image-viewer__mask",on:{click:function(t){return t.target!==t.currentTarget?null:e.handleMaskClick.apply(null,arguments)}}}),t("span",{staticClass:"el-image-viewer__btn el-image-viewer__close",on:{click:e.hide}},[t("i",{staticClass:"el-icon-close"})]),e.isSingle?e._e():[t("span",{staticClass:"el-image-viewer__btn el-image-viewer__prev",class:{"is-disabled":!e.infinite&&e.isFirst},on:{click:e.prev}},[t("i",{staticClass:"el-icon-arrow-left"})]),t("span",{staticClass:"el-image-viewer__btn el-image-viewer__next",class:{"is-disabled":!e.infinite&&e.isLast},on:{click:e.next}},[t("i",{staticClass:"el-icon-arrow-right"})])],t("div",{staticClass:"el-image-viewer__btn el-image-viewer__actions"},[t("div",{staticClass:"el-image-viewer__actions__inner"},[t("i",{staticClass:"el-icon-zoom-out",on:{click:function(t){return e.handleActions("zoomOut")}}}),t("i",{staticClass:"el-icon-zoom-in",on:{click:function(t){return e.handleActions("zoomIn")}}}),t("i",{staticClass:"el-image-viewer__actions__divider"}),t("i",{class:e.mode.icon,on:{click:e.toggleMode}}),t("i",{staticClass:"el-image-viewer__actions__divider"}),t("i",{staticClass:"el-icon-refresh-left",on:{click:function(t){return e.handleActions("anticlocelise")}}}),t("i",{staticClass:"el-icon-refresh-right",on:{click:function(t){return e.handleActions("clocelise")}}})])]),t("div",{staticClass:"el-image-viewer__canvas"},e._l(e.urlList,function(n,i){return i===e.index?t("img",{key:n,ref:"img",refInFor:!0,staticClass:"el-image-viewer__img",style:e.imgStyle,attrs:{src:e.currentImg},on:{load:e.handleImgLoad,error:e.handleImgError,mousedown:e.handleMouseDown}}):e._e()}),0)],2)])};i._withStripped=!0;var s=n(106),a=n.n(s);const o=a.a.prototype.$isServer,l=(o||Number(document.documentMode),!o&&document.addEventListener?function(e,t,n){e&&t&&n&&e.addEventListener(t,n,!1)}:function(e,t,n){e&&t&&n&&e.attachEvent("on"+t,n)}),r=!o&&document.removeEventListener?function(e,t,n){e&&t&&e.removeEventListener(t,n,!1)}:function(e,t,n){e&&t&&e.detachEvent("on"+t,n)};function hasClass(e,t){if(!e||!t)return!1;if(-1!==t.indexOf(" "))throw new Error("className should not contain space.");return e.classList?e.classList.contains(t):(" "+e.className+" ").indexOf(" "+t+" ")>-1}function addClass(e,t){if(e){for(var n=e.className,i=(t||"").split(" "),s=0,a=i.length;s<a;s++){var o=i[s];o&&(e.classList?e.classList.add(o):hasClass(e,o)||(n+=" "+o))}e.classList||e.setAttribute("class",n)}}function removeClass(e,t){if(e&&t){for(var n=t.split(" "),i=" "+e.className+" ",s=0,a=n.length;s<a;s++){var o=n[s];o&&(e.classList?e.classList.remove(o):hasClass(e,o)&&(i=i.replace(" "+o+" "," ")))}e.classList||e.setAttribute("class",(i||"").replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,""))}}let isFunction=e=>e&&"[object Function]"==={}.toString.call(e);"object"==typeof Int8Array||!a.a.prototype.$isServer&&document.childNodes;Object.prototype.hasOwnProperty;function rafThrottle(e){let t=!1;return function(...n){t||(t=!0,window.requestAnimationFrame(i=>{e.apply(this,n),t=!1}))}}let d,c=!1,h=!1;const getModal=function(){if(a.a.prototype.$isServer)return;let e=m.modalDom;return e?c=!0:(c=!1,e=document.createElement("div"),m.modalDom=e,e.addEventListener("touchmove",function(e){e.preventDefault(),e.stopPropagation()}),e.addEventListener("click",function(){m.doOnModalClick&&m.doOnModalClick()})),e},u={},m={modalFade:!0,getInstance:function(e){return u[e]},register:function(e,t){e&&t&&(u[e]=t)},deregister:function(e){e&&(u[e]=null,delete u[e])},nextZIndex:function(){return m.zIndex++},modalStack:[],doOnModalClick:function(){const e=m.modalStack[m.modalStack.length-1];if(!e)return;const t=m.getInstance(e.id);t&&t.closeOnClickModal&&t.close()},openModal:function(e,t,n,i,s){if(a.a.prototype.$isServer)return;if(!e||void 0===t)return;this.modalFade=s;const o=this.modalStack;for(let t=0,n=o.length;t<n;t++){if(o[t].id===e)return}const l=getModal();if(addClass(l,"v-modal"),this.modalFade&&!c&&addClass(l,"v-modal-enter"),i){i.trim().split(/\s+/).forEach(e=>addClass(l,e))}setTimeout(()=>{removeClass(l,"v-modal-enter")},200),n&&n.parentNode&&11!==n.parentNode.nodeType?n.parentNode.appendChild(l):document.body.appendChild(l),t&&(l.style.zIndex=t),l.tabIndex=0,l.style.display="",this.modalStack.push({id:e,zIndex:t,modalClass:i})},closeModal:function(e){const t=this.modalStack,n=getModal();if(t.length>0){const i=t[t.length-1];if(i.id===e){if(i.modalClass){i.modalClass.trim().split(/\s+/).forEach(e=>removeClass(n,e))}t.pop(),t.length>0&&(n.style.zIndex=t[t.length-1].zIndex)}else for(let n=t.length-1;n>=0;n--)if(t[n].id===e){t.splice(n,1);break}}0===t.length&&(this.modalFade&&addClass(n,"v-modal-leave"),setTimeout(()=>{0===t.length&&(n.parentNode&&n.parentNode.removeChild(n),n.style.display="none",m.modalDom=void 0),removeClass(n,"v-modal-leave")},200))}};Object.defineProperty(m,"zIndex",{configurable:!0,get:()=>(h||(d=d||(a.a.prototype.$ELEMENT||{}).zIndex||2e3,h=!0),d),set(e){d=e}});a.a.prototype.$isServer||window.addEventListener("keydown",function(e){if(27===e.keyCode){const e=function(){if(!a.a.prototype.$isServer&&m.modalStack.length>0){const e=m.modalStack[m.modalStack.length-1];if(!e)return;return m.getInstance(e.id)}}();e&&e.closeOnPressEscape&&(e.handleClose?e.handleClose():e.handleAction?e.handleAction("cancel"):e.close())}});var f=m;Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean;const p={CONTAIN:{name:"contain",icon:"el-icon-full-screen"},ORIGINAL:{name:"original",icon:"el-icon-c-scale-to-original"}},g=!a.a.prototype.$isServer&&window.navigator.userAgent.match(/firefox/i)?"DOMMouseScroll":"mousewheel";var v={name:"elImageViewer",props:{urlList:{type:Array,default:()=>[]},zIndex:{type:Number,default:2e3},onSwitch:{type:Function,default:()=>{}},onClose:{type:Function,default:()=>{}},initialIndex:{type:Number,default:0},appendToBody:{type:Boolean,default:!0},maskClosable:{type:Boolean,default:!0}},data(){return{index:this.initialIndex,isShow:!1,infinite:!0,loading:!1,mode:p.CONTAIN,transform:{scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}}},computed:{isSingle(){return this.urlList.length<=1},isFirst(){return 0===this.index},isLast(){return this.index===this.urlList.length-1},currentImg(){return this.urlList[this.index]},imgStyle(){const{scale:e,deg:t,offsetX:n,offsetY:i,enableTransition:s}=this.transform,a={transform:`scale(${e}) rotate(${t}deg)`,transition:s?"transform .3s":"","margin-left":`${n}px`,"margin-top":`${i}px`};return this.mode===p.CONTAIN&&(a.maxWidth=a.maxHeight="100%"),a},viewerZIndex(){const e=f.nextZIndex();return this.zIndex>e?this.zIndex:e}},watch:{index:{handler:function(e){this.reset(),this.onSwitch(e)}},currentImg(e){this.$nextTick(e=>{this.$refs.img[0].complete||(this.loading=!0)})}},methods:{hide(){this.deviceSupportUninstall(),this.onClose()},deviceSupportInstall(){this._keyDownHandler=e=>{e.stopPropagation();switch(e.keyCode){case 27:this.hide();break;case 32:this.toggleMode();break;case 37:this.prev();break;case 38:this.handleActions("zoomIn");break;case 39:this.next();break;case 40:this.handleActions("zoomOut")}},this._mouseWheelHandler=rafThrottle(e=>{(e.wheelDelta?e.wheelDelta:-e.detail)>0?this.handleActions("zoomIn",{zoomRate:.015,enableTransition:!1}):this.handleActions("zoomOut",{zoomRate:.015,enableTransition:!1})}),l(document,"keydown",this._keyDownHandler),l(document,g,this._mouseWheelHandler)},deviceSupportUninstall(){r(document,"keydown",this._keyDownHandler),r(document,g,this._mouseWheelHandler),this._keyDownHandler=null,this._mouseWheelHandler=null},handleImgLoad(e){this.loading=!1},handleImgError(e){this.loading=!1,e.target.alt="加载失败"},handleMouseDown(e){if(this.loading||0!==e.button)return;const{offsetX:t,offsetY:n}=this.transform,i=e.pageX,s=e.pageY;this._dragHandler=rafThrottle(e=>{this.transform.offsetX=t+e.pageX-i,this.transform.offsetY=n+e.pageY-s}),l(document,"mousemove",this._dragHandler),l(document,"mouseup",e=>{r(document,"mousemove",this._dragHandler)}),e.preventDefault()},handleMaskClick(){this.maskClosable&&this.hide()},reset(){this.transform={scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}},toggleMode(){if(this.loading)return;const e=Object.keys(p),t=(Object.values(p).indexOf(this.mode)+1)%e.length;this.mode=p[e[t]],this.reset()},prev(){if(this.isFirst&&!this.infinite)return;const e=this.urlList.length;this.index=(this.index-1+e)%e},next(){if(this.isLast&&!this.infinite)return;const e=this.urlList.length;this.index=(this.index+1)%e},handleActions(e,t={}){if(this.loading)return;const{zoomRate:n,rotateDeg:i,enableTransition:s}={zoomRate:.2,rotateDeg:90,enableTransition:!0,...t},{transform:a}=this;switch(e){case"zoomOut":a.scale>.2&&(a.scale=parseFloat((a.scale-n).toFixed(3)));break;case"zoomIn":a.scale=parseFloat((a.scale+n).toFixed(3));break;case"clocelise":a.deg+=i;break;case"anticlocelise":a.deg-=i}a.enableTransition=s}},mounted(){this.deviceSupportInstall(),this.appendToBody&&document.body.appendChild(this.$el),this.$refs["el-image-viewer__wrapper"].focus()},destroyed(){this.appendToBody&&this.$el&&this.$el.parentNode&&this.$el.parentNode.removeChild(this.$el)}},w=n(3),_=Object(w.a)(v,i,[],!1,null,null,null);t.default=_.exports}}]);
@@ -1,202 +0,0 @@
1
- // src/directives/autoScroll.js
2
- export default {
3
- inserted(el, binding) {
4
- // 核心配置:新增scrollMode切换模式
5
- const {
6
- scrollMode = 'pixel', // 滚动模式:pixel(逐像素)/screen(按屏)
7
- speed = 1, // 【像素模式】每次滚动像素(仅pixel生效)
8
- scrollStep = 1, // 【屏模式】每次滚动屏数(仅screen生效)
9
- scrollInterval = 50, // 【屏模式】整屏间隔(ms);【像素模式】定时器间隔(ms)
10
- direction = 'vertical', // vertical/horizontal
11
- loop = true, // 是否循环
12
- hideScrollbar = true, // 是否隐藏滚动条
13
- delay = 3000 // 手动滚动后恢复延迟
14
- } = binding.value || {};
15
-
16
- let timer = null;
17
- let isManualScroll = false;
18
- let currentScreen = 0; // 【屏模式】记录当前屏数
19
-
20
- // ========== 1. 自动隐藏滚动条 ==========
21
- if (hideScrollbar) {
22
- const originalStyle = el.style.cssText;
23
- el.style.cssText = `${originalStyle};
24
- scrollbar-width: none !important;
25
- -ms-overflow-style: none !important;
26
- `;
27
- const elId = el.id || 'auto-scroll-' + Date.now();
28
- if (!el.id) el.id = elId;
29
- const style = document.createElement('style');
30
- style.innerHTML = `
31
- #${elId}::-webkit-scrollbar {
32
- display: none !important;
33
- width: 0 !important;
34
- height: 0 !important;
35
- }
36
- `;
37
- document.head.appendChild(style);
38
- el._scrollbarStyle = style;
39
- }
40
-
41
- // ========== 2. 通用工具函数 ==========
42
- // 获取单屏尺寸(高度/宽度)
43
- const getScreenSize = () => {
44
- return direction === 'vertical' ? el.clientHeight : el.clientWidth;
45
- };
46
- // 获取总屏数(仅屏模式生效)
47
- const getTotalScreen = () => {
48
- const contentSize = direction === 'vertical' ? el.scrollHeight : el.scrollWidth;
49
- const screenSize = getScreenSize();
50
- return Math.ceil((contentSize - screenSize) / screenSize) + 1;
51
- };
52
- // 验证是否可滚动
53
- const checkScrollAble = () => {
54
- if (scrollMode === 'pixel') {
55
- return direction === 'vertical'
56
- ? el.scrollHeight > el.clientHeight
57
- : el.scrollWidth > el.clientWidth;
58
- } else {
59
- return getTotalScreen() > 1;
60
- }
61
- };
62
-
63
- // ========== 3. 双模式滚动核心逻辑 ==========
64
- // 【像素模式】逐像素滚动
65
- const pixelScroll = () => {
66
- if (!checkScrollAble() || isManualScroll) return;
67
-
68
- if (direction === 'vertical') {
69
- let nextPos = el.scrollTop + speed
70
- el.scrollTop += speed;
71
- if (loop && el.scrollTop >= el.scrollHeight - el.clientHeight - 1) {
72
- el.scrollTop = 0;
73
- }
74
- } else {
75
- el.scrollLeft += speed;
76
- if (loop && el.scrollLeft >= el.scrollWidth - el.clientWidth) {
77
- el.scrollLeft = 0;
78
- }
79
- }
80
- };
81
-
82
- // 【屏模式】整屏滚动
83
- const screenScroll = () => {
84
- if (!checkScrollAble() || isManualScroll) return;
85
-
86
- const screenSize = getScreenSize();
87
- const totalScreen = getTotalScreen();
88
-
89
- // 更新当前屏数
90
- currentScreen += scrollStep;
91
- // 循环逻辑
92
- if (loop && currentScreen >= totalScreen) {
93
- currentScreen = 0;
94
- }
95
- // 非循环:到最后一屏停止
96
- if (!loop && currentScreen >= totalScreen - 1) {
97
- clearInterval(timer);
98
- timer = null;
99
- console.log('【屏模式】已滚动到最后一屏,停止');
100
- return;
101
- }
102
-
103
- // 执行整屏滚动
104
- const targetPos = currentScreen * screenSize;
105
- if (direction === 'vertical') {
106
- el.scrollTop = targetPos;
107
- } else {
108
- el.scrollLeft = targetPos;
109
- }
110
- console.log(`【屏模式】切换到第${currentScreen + 1}屏,目标位置:${targetPos}px`);
111
- };
112
-
113
- // 统一滚动入口(根据模式选择逻辑)
114
- const autoScroll = () => {
115
- if (scrollMode === 'pixel') {
116
- pixelScroll();
117
- } else {
118
- screenScroll();
119
- }
120
- };
121
-
122
- // ========== 4. 启动/停止控制 ==========
123
- const startScroll = () => {
124
- if (!timer) {
125
- // 像素模式默认间隔16ms(流畅),屏模式用配置的scrollInterval
126
- const interval = scrollMode === 'pixel' ? (scrollInterval || 16) : scrollInterval;
127
- timer = setInterval(autoScroll, interval);
128
- console.log(`【${scrollMode}模式】滚动已启动,间隔${interval}ms`);
129
- }
130
- };
131
-
132
- const stopScroll = () => {
133
- if (timer) {
134
- clearInterval(timer);
135
- timer = null;
136
- console.log(`【${scrollMode}模式】滚动已暂停`);
137
- }
138
- };
139
-
140
- // ========== 5. 手动滚动兼容 ==========
141
- el.addEventListener('wheel', (e) => {
142
- isManualScroll = true;
143
- // 屏模式:同步当前屏数
144
- if (scrollMode === 'screen') {
145
- const screenSize = getScreenSize();
146
- currentScreen = direction === 'vertical'
147
- ? Math.floor(el.scrollTop / screenSize)
148
- : Math.floor(el.scrollLeft / screenSize);
149
- }
150
- // 延迟恢复
151
- setTimeout(() => {
152
- isManualScroll = false;
153
- }, delay);
154
- }, { passive: true });
155
-
156
- el.addEventListener('mousedown', () => {
157
- isManualScroll = true;
158
- }, { passive: true });
159
-
160
- document.addEventListener('mouseup', () => {
161
- // 屏模式:同步当前屏数
162
- if (scrollMode === 'screen') {
163
- const screenSize = getScreenSize();
164
- currentScreen = direction === 'vertical'
165
- ? Math.floor(el.scrollTop / screenSize)
166
- : Math.floor(el.scrollLeft / screenSize);
167
- }
168
- // 延迟恢复
169
- setTimeout(() => {
170
- isManualScroll = false;
171
- }, delay);
172
- }, { passive: true });
173
-
174
- // hover暂停/恢复
175
- el.addEventListener('mouseenter', stopScroll, { passive: true });
176
- el.addEventListener('mouseleave', startScroll, { passive: true });
177
-
178
- // 延迟启动
179
- setTimeout(() => {
180
- startScroll();
181
- }, 100);
182
-
183
- // 挂载变量
184
- el._autoScroll = { timer, stopScroll, startScroll };
185
- },
186
-
187
- // 解绑清理
188
- unbind(el) {
189
- if (el._autoScroll?.timer) {
190
- clearInterval(el._autoScroll.timer);
191
- }
192
- if (el._scrollbarStyle) {
193
- document.head.removeChild(el._scrollbarStyle);
194
- delete el._scrollbarStyle;
195
- }
196
- if (el.id && el.id.startsWith('auto-scroll-')) {
197
- el.removeAttribute('id');
198
- }
199
- delete el._autoScroll;
200
- console.log('【滚动指令】资源已清理');
201
- }
202
- };
package/src/index.js DELETED
@@ -1,87 +0,0 @@
1
-
2
- // 样式
3
- import '../components/theme-chalk/index.scss'
4
-
5
- // 日期
6
- import ZnDateLabel from '../components/date'
7
-
8
- // 字典
9
- import ZnDictLabel from '../components/dict/ZnDictLabel.vue'
10
- import ZnDictSelect from '../components/dict/ZnDictSelect.vue'
11
-
12
- // 动态组件
13
- import ZnDynamicRender from '../components/dynamic-component/ZnDynamicRender.vue'
14
- import RendererRegistry from "../components/dynamic-component/core/renderer-registry";
15
-
16
- // 金额
17
- import ZnMoneyLabel from '../components/money/ZnMoneyLabel.vue'
18
- import ZnMoneyInput from '../components/money/ZnMoneyInput.vue'
19
-
20
- // 列表详情
21
- import ZnDescriptions from '../components/descriptions/ZnDescriptions.js'
22
- import ZnDescriptionsItem from '../components/descriptions/ZnDescriptionsItem.vue'
23
-
24
- // 图片
25
- import ZnImageOperation from '../components/image/ZnImageOperation.vue'
26
- import ZnImage from '../components/image/ZnImage.js'
27
-
28
- // 导入组件
29
- import ZnExcelImport from "../components/import/ZnExcelImport";
30
-
31
- // 上传
32
- import ZnUpload from '../components/upload/ZnUpload.js'
33
-
34
- // Excel预览
35
- import ZnExcelPreview from '../components/import/ZnExcelPreview.js'
36
-
37
- // 描述组件
38
- import ZnDescription from '../components/descriptions/ZnDescriptions.js'
39
- import ZnDescriptionItem from '../components/descriptions/ZnDescriptionsItem.vue'
40
- import autoScroll from "./directives/autoScroll";
41
-
42
- const components = [
43
- ZnDateLabel,
44
- ZnDictLabel,
45
- ZnDictSelect,
46
- ZnDynamicRender,
47
- ZnMoneyLabel,
48
- ZnMoneyInput,
49
- ZnDescriptions,
50
- ZnDescriptionsItem,
51
- ZnImageOperation,
52
- ZnImage,
53
- ZnUpload,
54
- ZnExcelImport,
55
- ZnExcelPreview,
56
- ZnDescription,
57
- ZnDescriptionItem,
58
- ]
59
-
60
- const install = function(Vue) {
61
- // 注册所有组件
62
- components.forEach(component => {
63
- Vue.component(component.name, component)
64
- })
65
- Vue.directive('auto-scroll', autoScroll);
66
- // 全局注册组件注册中心(可选)
67
- Vue.prototype.$rendererRegistry = RendererRegistry
68
- }
69
-
70
- export default {
71
- install,
72
- ZnDateLabel,
73
- ZnDictLabel,
74
- ZnDictSelect,
75
- ZnDynamicRender,
76
- ZnMoneyLabel,
77
- ZnMoneyInput,
78
- ZnDescriptions,
79
- ZnDescriptionsItem,
80
- ZnImageOperation,
81
- ZnImage,
82
- ZnUpload,
83
- ZnExcelImport,
84
- ZnExcelPreview,
85
- ZnDescription,
86
- ZnDescriptionItem,
87
- }
@@ -1,59 +0,0 @@
1
- // src/index.index.onemap.js(仅 onemap 环境使用,包含 chunk 路径修正)
2
- // 第一步:注入 chunk 路径修正逻辑(核心)
3
- (function() {
4
- // 1. 全局变量存储 chunk 根路径
5
- window.ZnUI_CHUNK_BASE_URL = '';
6
-
7
- // 2. 暴露配置方法
8
- window.setZnUIChunkPath = function(baseUrl) {
9
- window.ZnUI_CHUNK_BASE_URL = baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`;
10
- console.log('[ZnUI] chunk 根路径已配置:', window.ZnUI_CHUNK_BASE_URL);
11
- if (typeof __webpack_require__ !== 'undefined') {
12
- __webpack_require__.p = window.ZnUI_CHUNK_BASE_URL;
13
- }
14
- };
15
-
16
- // 3. 重写 chunk 加载函数
17
- if (typeof __webpack_require__ !== 'undefined' && __webpack_require__.e) {
18
- const originalLoadChunk = __webpack_require__.e;
19
- __webpack_require__.e = function(chunkId) {
20
- return originalLoadChunk(chunkId).then(() => {
21
- const scripts = document.getElementsByTagName('script');
22
- Array.from(scripts).forEach(script => {
23
- if (script.src.match(/\d+\.zn-ui\.min\.js/) || script.src.includes('.zn-ui-chunk.js')) {
24
- if (!script.src.startsWith(window.ZnUI_CHUNK_BASE_URL)) {
25
- const chunkFileName = script.src.split('/').pop();
26
- const correctSrc = window.ZnUI_CHUNK_BASE_URL + chunkFileName;
27
- script.src = correctSrc;
28
- console.log('[ZnUI] 修正 chunk 路径:', correctSrc);
29
- }
30
- }
31
- });
32
- });
33
- };
34
- }
35
- })();
36
-
37
- // 第二步:导入通用入口的所有逻辑(复用组件代码,无需重复写)
38
- import ZnUILibrary from './index.js';
39
-
40
- // 第三步:扩展导出,添加 onemap 环境专属方法
41
- const ZnUIOnemap = {
42
- ...ZnUILibrary,
43
- setChunkPath: function(baseUrl) {
44
- window.ZnUI_CHUNK_BASE_URL = baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`;
45
- if (typeof __webpack_require__ !== 'undefined') {
46
- __webpack_require__.p = window.ZnUI_CHUNK_BASE_URL;
47
- }
48
- console.log('[ZnUI] 通过组件库对象配置 chunk 路径:', window.ZnUI_CHUNK_BASE_URL);
49
- }
50
- };
51
-
52
- // AMD 导出(保持模块名一致,使用方无需修改)
53
- if (typeof define === 'function' && define.amd) {
54
- define('ZnUI', [], () => ZnUIOnemap);
55
- } else {
56
- module.exports = ZnUIOnemap;
57
- }
58
-
59
- export default ZnUIOnemap;