app-form-view 0.0.5 → 0.0.7

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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * app-form-view.js v0.0.4
2
+ * app-form-view.js v0.0.6
3
3
  * Released under the MIT License.
4
4
  */
5
5
  !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("vuex"),require("element-ui"),require("vant")):"function"==typeof define&&define.amd?define(["exports","vue","vuex","element-ui","vant"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).AppFormView={},e.Vue,e.Vuex,e.ELEMENT,e.vant)}(this,function(e,t,n,i,a){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(t);function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=Array(t);n<t;n++)i[n]=e[n];return i}function l(e,t,n,i,a,r,o){try{var s=e[r](o),l=s.value}catch(e){return void n(e)}s.done?t(l):Promise.resolve(l).then(i,a)}function c(e){return function(){var t=this,n=arguments;return new Promise(function(i,a){var r=e.apply(t,n);function o(e){l(r,i,a,o,s,"next",e)}function s(e){l(r,i,a,o,s,"throw",e)}o(void 0)})}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function d(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,A(i.key),i)}}function p(e,t,n){return t&&d(e.prototype,t),n&&d(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function f(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=V(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,a=function(){};return{s:a,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,r=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw r}}}}function h(e,t,n){return(t=A(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)({}).hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},m.apply(null,arguments)}function v(e){if(null==e)throw new TypeError("Cannot destructure "+e)}function g(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,i)}return n}function y(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?g(Object(n),!0).forEach(function(t){h(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function b(e,t){if(null==e)return{};var n,i,a=function(e,t){if(null==e)return{};var n={};for(var i in e)if({}.hasOwnProperty.call(e,i)){if(-1!==t.indexOf(i))continue;n[i]=e[i]}return n}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(i=0;i<r.length;i++)n=r[i],-1===t.indexOf(n)&&{}.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}function w(){
@@ -168,7 +168,7 @@ localStorage.setItem("app-config",JSON.stringify(this.config))}},{key:"get",valu
168
168
  // ---------------- 关键修复:判断是否是 FormData ----------------
169
169
  t.data instanceof FormData?(t.contentType=!1,t.processData=!1,t.headers={}):["POST","PUT","PATCH"].includes(t.method.toUpperCase())&&t.data&&"application/x-www-form-urlencoded"===t.headers["Content-Type"]&&(t.data=B(t.data));
170
170
  // ----------------------------------------------------------------
171
- var a=function(e){var t;if(!1!==(null===(t=e.headers)||void 0===t?void 0:t.repeatSubmit)&&["POST","PUT"].includes(e.method.toUpperCase())){var n={url:e.url,data:e.data,time:(new Date).getTime()};if(JSON.stringify(n).length>=5242880)return console.warn("[".concat(e.url,"]: 请求数据超出5M限制")),e;M.session.setJSON("sessionObj",n)}return e}(t);return a?new Promise(function(e,t){$.ajax({cache:a.cache,processData:a.processData,contentType:a.contentType,url:a.url,type:a.method,data:a.data,headers:a.headers,timeout:a.timeout,success:function(n,r,o){try{var s=function(e){var t=e.data;if("blob"===e.responseType||"arraybuffer"===e.responseType)return t;var n=t.code,a=t.msg||"操作失败";return 401===n?Promise.reject("无效的会话,请重新登录"):500===n?(i.Message({message:a,type:"error"}),Promise.reject(a)):601===n?(i.Message({message:a,type:"warning"}),Promise.reject("warning")):0!==n&&void 0!==n?(i.Notification.error({title:a}),Promise.reject("error")):t}({data:n,responseType:a.responseType});e(s)}catch(e){t(e)}},error:function(e,n,a){(function(e,t,n){var a="";return a="error"===t?0===e.status?"后端接口连接异常":"系统接口".concat(e.status,"异常"):"timeout"===t?"请求超时":"请求失败: ".concat(n||t),i.Message({message:a,type:"error",duration:5e3}),Promise.reject(a)})(e,n,a).catch(t)}})}):Promise.reject("请求被拦截")};var q={data:function(){return{originCompConfig:{},eventMixinInited:!1,eventHandlersCache:{}}},watch:{"conf.events":{deep:!0,handler:function(e,t){this.eventMixinInited&&JSON.stringify(e)!==JSON.stringify(t)&&(this.unbindAllEvents(),this.initEventHandlers(),this.saveOriginCompConfig())}},value:{deep:!0,handler:function(e,t){this.eventMixinInited&&e!==t&&this.triggerEvent("change",{value:e,oldValue:t})}}},mounted:function(){this.conf?this.initEventMixin():console.warn("表单组件未配置 conf 参数,事件 mixin 初始化失败")},beforeDestroy:function(){this.unbindAllEvents(),this.eventMixinInited=!1},methods:{initEventMixin:function(){this.saveOriginCompConfig(),this.initEventHandlers(),this.triggerEvent("rendered"),this.eventMixinInited=!0},saveOriginCompConfig:function(){var e,t,n;this.originCompConfig={visible:!1!==this.conf.visible,disabled:!0===(null===(e=this.attrs)||void 0===e?void 0:e.disabled),required:!0===(null===(t=this.attrs)||void 0===t?void 0:t.required),readonly:!0===(null===(n=this.attrs)||void 0===n?void 0:n.readonly),value:this.value,refresh:this.conf.refresh||!1}},initEventHandlers:function(){var e,t=this,n=(null===(e=this.conf)||void 0===e?void 0:e.events)||[];Array.isArray(n)&&0!==n.length&&n.forEach(function(e){var n=e.type,i=e.rules;if(n&&Array.isArray(i))switch(n){case"change":break;case"click":case"focus":case"blur":t.bindDomEvent(n,i);break;case"rendered":t.executeRules(i);break;default:console.warn("不支持的事件类型:".concat(n))}})},bindDomEvent:function(e,t){var n=this,i=this.$el.querySelector("input, textarea, select, button, a");if(!i){var a=(this.$el.tagName?this.$el.tagName:"").toLowerCase();if(!["input","textarea","select","button","a"].includes(a))return;i=this.$el}var r=function(i){var a;i.stopPropagation(),i.preventDefault(),n.executeRules(t,{field:null===(a=n.attrs)||void 0===a?void 0:a.name,eventType:e,value:n.value})},o="".concat(e,"-").concat(this.uid||this.conf.id||Date.now());this.eventHandlersCache[o]={el:i,type:e,handler:r},i.addEventListener(e,r)},unbindAllEvents:function(){this.eventHandlersCache&&(Object.values(this.eventHandlersCache).forEach(function(e){e.el&&e.type&&e.handler&&e.el.removeEventListener(e.type,e.handler)}),this.eventHandlersCache={})},triggerEvent:function(e){var t,n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=((null===(t=this.conf)||void 0===t?void 0:t.events)||[]).find(function(t){return t.type===e});a&&Array.isArray(a.rules)&&this.executeRules(a.rules,y(y({},i),{},{field:null===(n=this.attrs)||void 0===n?void 0:n.name,eventType:e,component:this}))},executeRules:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Array.isArray(e)&&0!==e.length&&e.forEach(function(e){t.checkConditionGroups(e.conditionGroups,n)?t.executeActions(e.actions):t.restoreCompOriginState(e.actions)})},checkConditionGroups:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Array.isArray(e)||0===e.length)return!0;var i=!0;return e.forEach(function(e,a){var r=t.checkSingleConditionGroup(e,n);i=0===a?r:"and"===e.groupLogic?i&&r:i||r}),i},checkSingleConditionGroup:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=(null==e?void 0:e.conditions)||[];if(!Array.isArray(i)||0===i.length)return!0;var a=!0;return i.forEach(function(e,i){var r=t.checkSingleCondition(e,n);a=0===i?r:"and"===e.logic?a&&r:a||r}),a},checkSingleCondition:function(e){var t=e.field,n=e.operator,i=e.valueType,a=e.value;if(!t||!n)return!1;var r=this.getTargetFieldValue(t),o=this.getCompareValue(i,a);switch(n){case"=":return this.compareValues(r,o,"=");case"!=":return this.compareValues(r,o,"!=");case"like":return this.compareValues(r,o,"like");case">":return this.compareValues(r,o,">");case"<":return this.compareValues(r,o,"<");case">=":return this.compareValues(r,o,">=");case"<=":return this.compareValues(r,o,"<=");case"in":return this.compareValues(r,o,"in");case"is null":return null==r||""===r;case"is not null":return null!=r&&""!==r;default:return console.warn("不支持的运算符:".concat(n)),!1}},getTargetFieldValue:function(e){var t;return this.formData?this.formData[e]:e===(null===(t=this.attrs)||void 0===t?void 0:t.name)?this.value:void 0},getCompareValue:function(e,t){var n=this;if("fixed"===e)return t;if("form"===e){var i;if(Array.isArray(t)){var a=[];return t.forEach(function(e){void 0!==n.formData[e]&&a.push(n.formData[e])}),a}return(null===(i=this.formData)||void 0===i?void 0:i[t])||""}return t},compareValues:function(e,t,n){var i=null==e?"":String(e),a=null==t?"":String(t);switch(n){case"=":return i==a;case"!=":return i!==a;case"like":return i.includes(a);case">":return Number(i)>Number(a);case"<":return Number(i)<Number(a);case">=":return Number(i)>=Number(a);case"<=":return Number(i)<=Number(a);case"in":return Array.isArray(t)?t.includes(e):a.includes(i);default:return!1}},executeActions:function(e){var t=this;Array.isArray(e)&&0!==e.length&&e.forEach(function(e){var n=e.type,i=e.fields,a=e.setValueType,r=e.setFixedValue,o=e.setFormValue,s=e.message;
171
+ var a=function(e){var t;if(!1!==(null===(t=e.headers)||void 0===t?void 0:t.repeatSubmit)&&["POST","PUT"].includes(e.method.toUpperCase())){var n={url:e.url,data:e.data,time:(new Date).getTime()};if(JSON.stringify(n).length>=5242880)return console.warn("[".concat(e.url,"]: 请求数据超出5M限制")),e;M.session.setJSON("sessionObj",n)}return e}(t);return a?new Promise(function(e,t){$.ajax({cache:a.cache,processData:a.processData,contentType:a.contentType,url:a.url,type:a.method,data:a.data,headers:a.headers,timeout:a.timeout,success:function(n,r,o){try{var s=function(e){var t=e.data;if("blob"===e.responseType||"arraybuffer"===e.responseType)return t;var n=t.code,a=t.msg||"操作失败";return 401===n?Promise.reject("无效的会话,请重新登录"):500===n?(i.Message({message:a,type:"error"}),Promise.reject(a)):601===n?(i.Message({message:a,type:"warning"}),Promise.reject("warning")):0!==n&&void 0!==n?(i.Notification.error({title:a}),Promise.reject("error")):t}({data:n,responseType:a.responseType});e(s)}catch(e){t(e)}},error:function(e,n,a){(function(e,t,n){var a="";return a="error"===t?0===e.status?"后端接口连接异常":"系统接口".concat(e.status,"异常"):"timeout"===t?"请求超时":"请求失败: ".concat(n||t),i.Message({message:a,type:"error",duration:5e3}),Promise.reject(a)})(e,n,a).catch(t)}})}):Promise.reject("请求被拦截")};var q={data:function(){return{originCompConfig:{},eventMixinInited:!1,eventHandlersCache:{}}},watch:{"conf.events":{deep:!0,handler:function(e,t){this.eventMixinInited&&JSON.stringify(e)!==JSON.stringify(t)&&(this.unbindAllEvents(),this.initEventHandlers(),this.saveOriginCompConfig())}},value:{deep:!0,handler:function(e,t){this.eventMixinInited&&e!==t&&this.triggerEvent("change",{value:e,oldValue:t})}}},mounted:function(){this.conf?this.initEventMixin():console.warn("表单组件未配置 conf 参数,事件 mixin 初始化失败")},beforeDestroy:function(){this.unbindAllEvents(),this.eventMixinInited=!1},methods:{initEventMixin:function(){this.saveOriginCompConfig(),this.initEventHandlers(),this.triggerEvent("rendered"),this.eventMixinInited=!0},saveOriginCompConfig:function(){var e,t,n;this.originCompConfig={visible:!1!==this.conf.visible,disabled:!0===(null===(e=this.attrs)||void 0===e?void 0:e.disabled),required:!0===(null===(t=this.attrs)||void 0===t?void 0:t.required),readonly:!0===(null===(n=this.attrs)||void 0===n?void 0:n.readonly),value:this.value,refresh:this.conf.refresh||!1}},initEventHandlers:function(){var e,t=this,n=(null===(e=this.conf)||void 0===e?void 0:e.events)||[];Array.isArray(n)&&0!==n.length&&n.forEach(function(e){var n=e.type,i=e.rules;if(n&&Array.isArray(i))switch(n){case"change":break;case"click":case"focus":case"blur":t.bindDomEvent(n,i);break;case"rendered":t.executeRules(i);break;default:console.warn("不支持的事件类型:".concat(n))}})},bindDomEvent:function(e,t){var n=this,i=this.$el.querySelector("input, textarea, select, button, a");if(!i){var a=this.$el.tagName?this.$el.tagName:"";console.log(a,"events");var r=a.toLowerCase();if(!["input","textarea","select","button","a"].includes(r))return;i=this.$el}var o=function(i){var a;i.stopPropagation(),i.preventDefault(),n.executeRules(t,{field:null===(a=n.attrs)||void 0===a?void 0:a.name,eventType:e,value:n.value})},s="".concat(e,"-").concat(this.uid||this.conf.id||Date.now());this.eventHandlersCache[s]={el:i,type:e,handler:o},i.addEventListener(e,o)},unbindAllEvents:function(){this.eventHandlersCache&&(Object.values(this.eventHandlersCache).forEach(function(e){e.el&&e.type&&e.handler&&e.el.removeEventListener(e.type,e.handler)}),this.eventHandlersCache={})},triggerEvent:function(e){var t,n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=((null===(t=this.conf)||void 0===t?void 0:t.events)||[]).find(function(t){return t.type===e});a&&Array.isArray(a.rules)&&this.executeRules(a.rules,y(y({},i),{},{field:null===(n=this.attrs)||void 0===n?void 0:n.name,eventType:e,component:this}))},executeRules:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Array.isArray(e)&&0!==e.length&&e.forEach(function(e){t.checkConditionGroups(e.conditionGroups,n)?t.executeActions(e.actions):t.restoreCompOriginState(e.actions)})},checkConditionGroups:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Array.isArray(e)||0===e.length)return!0;var i=!0;return e.forEach(function(e,a){var r=t.checkSingleConditionGroup(e,n);i=0===a?r:"and"===e.groupLogic?i&&r:i||r}),i},checkSingleConditionGroup:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=(null==e?void 0:e.conditions)||[];if(!Array.isArray(i)||0===i.length)return!0;var a=!0;return i.forEach(function(e,i){var r=t.checkSingleCondition(e,n);a=0===i?r:"and"===e.logic?a&&r:a||r}),a},checkSingleCondition:function(e){var t=e.field,n=e.operator,i=e.valueType,a=e.value;if(!t||!n)return!1;var r=this.getTargetFieldValue(t),o=this.getCompareValue(i,a);switch(n){case"=":return this.compareValues(r,o,"=");case"!=":return this.compareValues(r,o,"!=");case"like":return this.compareValues(r,o,"like");case">":return this.compareValues(r,o,">");case"<":return this.compareValues(r,o,"<");case">=":return this.compareValues(r,o,">=");case"<=":return this.compareValues(r,o,"<=");case"in":return this.compareValues(r,o,"in");case"is null":return null==r||""===r;case"is not null":return null!=r&&""!==r;default:return console.warn("不支持的运算符:".concat(n)),!1}},getTargetFieldValue:function(e){var t;return this.formData?this.formData[e]:e===(null===(t=this.attrs)||void 0===t?void 0:t.name)?this.value:void 0},getCompareValue:function(e,t){var n=this;if("fixed"===e)return t;if("form"===e){var i;if(Array.isArray(t)){var a=[];return t.forEach(function(e){void 0!==n.formData[e]&&a.push(n.formData[e])}),a}return(null===(i=this.formData)||void 0===i?void 0:i[t])||""}return t},compareValues:function(e,t,n){var i=null==e?"":String(e),a=null==t?"":String(t);switch(n){case"=":return i==a;case"!=":return i!==a;case"like":return i.includes(a);case">":return Number(i)>Number(a);case"<":return Number(i)<Number(a);case">=":return Number(i)>=Number(a);case"<=":return Number(i)<=Number(a);case"in":return Array.isArray(t)?t.includes(e):a.includes(i);default:return!1}},executeActions:function(e){var t=this;Array.isArray(e)&&0!==e.length&&e.forEach(function(e){var n=e.type,i=e.fields,a=e.setValueType,r=e.setFixedValue,o=e.setFormValue,s=e.message;
172
172
  // 全局表单动作(走自己这一层)
173
173
  ["saveForm","saveAndCloseForm","closeForm","resetForm"].includes(n)?t.triggerGlobalFormEvent(n):
174
174
  // ===================== 核心修改 =====================
@@ -447,7 +447,7 @@ onFinish:function(e){var t=e.selectedOptions;this.innerValue=t[t.length-1].value
447
447
  // this.showText = selectedOptions.map(item => item.text).join(' / ');
448
448
  this.showText=t[t.length-1].text,this.showPicker=!1}},mounted:function(){this.refreshData()}},pe={render:function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("van-field",{class:e.attrs.class,attrs:{name:e.attrs.name,label:e.conf.hideLabel?"":e.conf.label,rules:e.rules},scopedSlots:e._u([{key:"input",fn:function(){return[n("van-uploader",e._b({attrs:{name:e.attrs.name,"after-read":e.afterRead,"upload-icon":"plus"},on:{oversize:e.onOversize,delete:e.onDelete},scopedSlots:e._u([{key:"preview-cover",fn:function(t){var i=t.file,a=t.content;return[n("div",{staticClass:"download-btn",on:{click:function(t){return t.stopPropagation(),e.handleDownload(i,a)}}},[n("van-icon",{attrs:{name:"down",color:"#fff"}})],1)]}}]),model:{value:e.fileList,callback:function(t){e.fileList=t},expression:"fileList"}},"van-uploader",e.filterAttrs,!1))]},proxy:!0}])})},staticRenderFns:[],props:{conf:{type:Object,default:function(){return{}}},attrs:{type:Object,default:function(){return{}}},value:{type:[Array,Object,String],default:""},mode:{type:String,default:"preview"}},mixins:[q],inject:["formData","updateFormData"],data:function(){return{innerValue:this.formatToJsonString(this.value),fileList:[]}},computed:{isImg:function(){var e=this.conf.allowedFileType;return Array.isArray(e)&&e.includes("image")&&1==e.length},filterAttrs:function(){var e=this.attrs,t=e.multiple,n=e.readonly,i=e.disabled,a=this.conf,r=a.allowedFileType,o=void 0===r?[]:r;a.minFileCount;var s=a.maxFileCount,l=a.maxFileSize,c=Array.isArray(o)&&o.includes("image")&&1==o.length,u={};if(t&&(u.multiple=!0,s&&s>1&&(u.maxCount=s)),l&&(u.maxSize=1024*l),(n||i||"view"==this.mode)&&(u.deletable=!1,u.showUpload=!1,u.previewFullImage=!0),u.disabled=!1,c)u.accept="image/*";else if(o.includes("apk"))u.accept=".apk";else{var d=[];o.includes("pdf")&&d.push(".pdf"),o.includes("office")&&d.push(".doc,.docx,.xls,.xlsx,.ppt,.pptx"),o.includes("zip")&&d.push(".zip,.rar,.7z"),o.includes("image")&&d.push(".png,.jpg,.jpeg,.gif,.webp"),u.accept=d.join(",")}return u}},watch:{value:function(e){var t=this.formatToJsonString(e);this.innerValue=t,this.fileList="[]"===t||""===t?[]:this.syncFileObjectsFromBase64()}},created:function(){this.fileList=this.syncFileObjectsFromBase64()},methods:{onDelete:function(e,t){var n=t.index;this.afterRead(),console.log("已删除",e.url,n)},onOversize:function(e){this.$toast("文件大小不能超过"+(this.conf.maxFileSize||0)+"KB")},afterRead:function(e){this.getStringValue(),this.$emit("input",this.innerValue)},getStringValue:function(){var e=this;this.innerValue=JSON.stringify(this.fileList.map(function(t){var n={},i=e.conf.keyMap.name||"name",a=e.conf.keyMap.size||"size",r=e.conf.keyMap.type||"type",o=e.conf.keyMap.path||"path",s=e.conf.keyMap.bizType||"bizType";n[i]=t.file.name,n[a]=t.file.size;
449
449
  // 修复:兜底空字符串再小写
450
- var l=t.file.name.split("."),c=((l.length>1?l.pop():"")||"").toLowerCase();return n[r]=c,n[o]=t.content,e.attrs.name&&e.attrs.name.split("@").length>1&&(n[s]=e.attrs.name.split("@").pop()),n}))},formatToJsonString:function(e){return e?"string"==typeof e?e.trim()||"[]":JSON.stringify(e):"[]"},parseValueToArray:function(){try{if(!this.innerValue)return[];var e="string"==typeof this.innerValue?JSON.parse(this.innerValue):this.innerValue;return Array.isArray(e)?e:e?[e]:[]}catch(e){return console.error("解析文件数据失败",e),[]}},syncFileObjectsFromBase64:function(){var e=this,t=this.parseValueToArray();if(!t.length)return[];var n=[];return t.forEach(function(t){try{var i=t[e.conf.keyMap.path||"path"];if(!i)return;var a=e.conf.keyMap.name||"name",r=e.conf.keyMap.type||"type",o=
450
+ var l=t.file.name.split("."),c=l.length>1?l.pop():"",u=(c||"").toLowerCase();return console.log(c,u,"inputUpload"),n[r]=u,n[o]=t.content,e.attrs.name&&e.attrs.name.split("@").length>1&&(n[s]=e.attrs.name.split("@").pop()),n}))},formatToJsonString:function(e){return e?"string"==typeof e?e.trim()||"[]":JSON.stringify(e):"[]"},parseValueToArray:function(){try{if(!this.innerValue)return[];var e="string"==typeof this.innerValue?JSON.parse(this.innerValue):this.innerValue;return Array.isArray(e)?e:e?[e]:[]}catch(e){return console.error("解析文件数据失败",e),[]}},syncFileObjectsFromBase64:function(){var e=this,t=this.parseValueToArray();if(!t.length)return[];var n=[];return t.forEach(function(t){try{var i=t[e.conf.keyMap.path||"path"];if(!i)return;var a=e.conf.keyMap.name||"name",r=e.conf.keyMap.type||"type",o=
451
451
  /**
452
452
  * 万能 Base64 转 File 对象
453
453
  * @param {string} base64Data - 完整 base64(带前缀或纯 base64)
@@ -484,7 +484,7 @@ function(e){return{"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image
484
484
  // 5. Base64 转 Blob 再转 File
485
485
  try{for(var l=atob(i),c=new Uint8Array(l.length),u=0;u<l.length;u++)c[u]=l.charCodeAt(u);var d=new Blob([c],{type:r});return new File([d],s,{type:r})}catch(e){return console.error("Base64 转 File 失败:",e),null}}(i,t[a]||"file");if(o&&(o.name.endsWith(".bin")||"application/octet-stream"===o.type)){var s="",l=t[a]||"",c=t[r]||"",u=l.toLowerCase(),d=c.toLowerCase();
486
486
  // 修复:兜底空字符串,防止 undefined.toLowerCase
487
- if(d?s=d:u&&(u.endsWith(".png")?s="image/png":u.endsWith(".jpg")||u.endsWith(".jpeg")?s="image/jpeg":u.endsWith(".gif")?s="image/gif":u.endsWith(".pdf")?s="application/pdf":u.endsWith(".zip")?s="application/zip":u.endsWith(".docx")?s="application/vnd.openxmlformats-officedocument.wordprocessingml.document":u.endsWith(".xlsx")?s="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":u.endsWith(".pptx")?s="application/vnd.openxmlformats-officedocument.presentationml.presentation":u.endsWith(".doc")?s="application/msword":u.endsWith(".xls")?s="application/vnd.ms-excel":u.endsWith(".ppt")&&(s="application/vnd.ms-powerpoint")),!s&&i.includes("UEsDBBQ")&&(s="application/vnd.openxmlformats-officedocument.wordprocessingml.document"),s){for(var p=x(i.split(","),2)[1],f=atob(p),h=new Uint8Array(f.length),m=0;m<f.length;m++)h[m]=f.charCodeAt(m);var v=new Blob([h],{type:s}),g=e.getExtensionByMimeType(s),y=t[a]||"file.".concat(g);o=new File([v],y,{type:s})}}o&&n.push({file:o,content:i,url:i,message:o.name,status:""})}catch(e){console.error("回显文件失败:",e)}}),n},
487
+ if(console.log(l,c,"rawType"),d?s=d:u&&(u.endsWith(".png")?s="image/png":u.endsWith(".jpg")||u.endsWith(".jpeg")?s="image/jpeg":u.endsWith(".gif")?s="image/gif":u.endsWith(".pdf")?s="application/pdf":u.endsWith(".zip")?s="application/zip":u.endsWith(".docx")?s="application/vnd.openxmlformats-officedocument.wordprocessingml.document":u.endsWith(".xlsx")?s="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":u.endsWith(".pptx")?s="application/vnd.openxmlformats-officedocument.presentationml.presentation":u.endsWith(".doc")?s="application/msword":u.endsWith(".xls")?s="application/vnd.ms-excel":u.endsWith(".ppt")&&(s="application/vnd.ms-powerpoint")),!s&&i.includes("UEsDBBQ")&&(s="application/vnd.openxmlformats-officedocument.wordprocessingml.document"),s){for(var p=x(i.split(","),2)[1],f=atob(p),h=new Uint8Array(f.length),m=0;m<f.length;m++)h[m]=f.charCodeAt(m);var v=new Blob([h],{type:s}),g=e.getExtensionByMimeType(s),y=t[a]||"file.".concat(g);o=new File([v],y,{type:s})}}o&&n.push({file:o,content:i,url:i,message:o.name,status:""})}catch(e){console.error("回显文件失败:",e)}}),n},
488
488
  // 下载文件
489
489
  handleDownload:function(e,t){if(e&&t){for(var n=x(t.split(","),2),i=n[0],a=n[1],r=atob(a),o=[],s=0;s<r.length;s++)o.push(r.charCodeAt(s));var l=new Blob([new Uint8Array(o)],{type:i||"application/octet-stream"}),c=URL.createObjectURL(l),u=document.createElement("a");u.href=c,u.download=(null==e?void 0:e.name)||"file",document.body.appendChild(u),u.click(),document.body.removeChild(u),URL.revokeObjectURL(c)}else this.$toast("文件不存在")},getExtensionByMimeType:function(e){return{"image/png":"png","image/jpeg":"jpg","image/gif":"gif","application/pdf":"pdf","application/zip":"zip"}[e]||"file"}}},fe={render:function(){var e=this,t=e.$createElement,n=e._self._c||t;return"view"==e.mode?n("div",{staticClass:"view-value"},[e._v(e._s(e.innerValue||"-"))]):n("div",{staticClass:"input-group"},[n("input",e._b({ref:"suggestInput",attrs:{type:"text",placeholder:e.conf.placeholder||"请选择",disabled:e.conf.disabled||e.loading},domProps:{value:e.innerValue}},"input",e.attrs,!1)),e._v(" "),n("div",{staticClass:"input-group-btn"},[n("button",{staticClass:"btn btn-white dropdown-toggle",attrs:{type:"button","data-toggle":"dropdown",disabled:e.conf.disabled||e.loading}},[n("span",{staticClass:"caret"})]),e._v(" "),n("ul",{staticClass:"dropdown-menu dropdown-menu-right",attrs:{role:"menu"}})])])},staticRenderFns:[],mixins:[G,q],data:function(){return{loading:!1,suggestInstance:null}},mounted:function(){this.initBsSuggest()},beforeDestroy:function(){this.suggestInstance&&(this.$refs.suggestInput.bsSuggest("destroy"),this.suggestInstance=null)},methods:{initBsSuggest:function(){var e=this,t=this.conf.api,n=$(this.$refs.suggestInput),i={};t.headers.forEach(function(e){e.field&&e.label&&(i[e.field]=e.label)});
490
490
  // 2. effectiveFields(搜索匹配的字段)
@@ -569,4 +569,4 @@ this.$emit("updateItem","label",t)}}},watch:{
569
569
  // 监听conf.label变化,同步到可编辑元素(解决父组件数据更新时子组件不刷新的问题)
570
570
  "conf.label":function(e){var t=this.$refs.editableElement;t&&t.textContent!==e&&(t.textContent=e)}}},AppTable:ge,AppButton:{render:function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("a",{class:e.conf.buttonType,style:e.style,attrs:{disabled:e.conf.disabled}},[e.conf.icon?n("i",{staticClass:"icon",class:e.conf.icon}):e._e(),e._v(" "),n("span",[e._v(e._s(e.conf.buttonText))])])},staticRenderFns:[],mixins:[X,q],data:function(){return{}},computed:{style:function(){return void 0!==this.conf.appWidth?{width:"".concat(this.conf.appWidth/12*100,"%")}:{}}},methods:{refreshCallback:function(){this.updateCallback()}}},AppLayoutBlock:{render:function(){var e=this,t=e.$createElement;return(e._self._c||t)("div",{class:["clearfix",e.conf.align].concat(e.conf.border&&e.conf.border.length>0?e.conf.border:[])},[e._t("default")],2)},staticRenderFns:[],props:{mode:{type:String,default:"preview"},conf:{
571
571
  // 表单数据对象
572
- type:Object,required:!0},formConf:{type:Object}},data:function(){return{}},methods:{}}},be=function(e){be.installed||(be.installed=!0,options.request&&(e.prototype.$request=options.request),Object.values(ye).forEach(function(t){e.component(t.name,t)}))},we=y({install:be},ye),Ce=ye.AppFormView,xe=ye.AppForm,ke=ye.AppFormItem,Ae=ye.AppSubRow,Te=ye.AppInput,Ve=ye.AppTextBox,Se=ye.AppInputHidden,_e=ye.AppSelect,je=ye.AppRadio,De=ye.AppCheckbox,Ie=ye.AppDateTimePicker,$e=ye.AppDateTimeRange,Le=ye.AppInputTree,Oe=ye.AppInputUpload,Fe=ye.AppSearchSelect,Re=ye.AppSearchApi,Pe=ye.AppSubTitle,Ee=ye.AppTable,Ne=ye.AppButton,ze=ye.AppLayoutBlock;e.AppFormView=Ce,e.CAppButton=Ne,e.CAppCheckbox=De,e.CAppDateTimePicker=Ie,e.CAppDateTimeRange=$e,e.CAppForm=xe,e.CAppFormItem=ke,e.CAppInput=Te,e.CAppInputHidden=Se,e.CAppInputTree=Le,e.CAppInputUpload=Oe,e.CAppLayoutBlock=ze,e.CAppRadio=je,e.CAppSearchApi=Re,e.CAppSearchSelect=Fe,e.CAppSelect=_e,e.CAppSubRow=Ae,e.CAppSubTitle=Pe,e.CAppTable=Ee,e.CAppTextBox=Ve,e.default=we,Object.defineProperty(e,"__esModule",{value:!0})});
572
+ type:Object,required:!0},formConf:{type:Object}},data:function(){return{}},methods:{}}},be=function(e,t){be.installed||(be.installed=!0,t.request&&(e.prototype.$request=t.request),Object.values(ye).forEach(function(t){e.component(t.name,t)}))},we=y({install:be},ye),Ce=ye.AppFormView,xe=ye.AppForm,ke=ye.AppFormItem,Ae=ye.AppSubRow,Te=ye.AppInput,Ve=ye.AppTextBox,Se=ye.AppInputHidden,_e=ye.AppSelect,je=ye.AppRadio,De=ye.AppCheckbox,Ie=ye.AppDateTimePicker,$e=ye.AppDateTimeRange,Le=ye.AppInputTree,Oe=ye.AppInputUpload,Fe=ye.AppSearchSelect,Re=ye.AppSearchApi,Pe=ye.AppSubTitle,Ee=ye.AppTable,Ne=ye.AppButton,ze=ye.AppLayoutBlock;e.AppFormView=Ce,e.CAppButton=Ne,e.CAppCheckbox=De,e.CAppDateTimePicker=Ie,e.CAppDateTimeRange=$e,e.CAppForm=xe,e.CAppFormItem=ke,e.CAppInput=Te,e.CAppInputHidden=Se,e.CAppInputTree=Le,e.CAppInputUpload=Oe,e.CAppLayoutBlock=ze,e.CAppRadio=je,e.CAppSearchApi=Re,e.CAppSearchSelect=Fe,e.CAppSelect=_e,e.CAppSubRow=Ae,e.CAppSubTitle=Pe,e.CAppTable=Ee,e.CAppTextBox=Ve,e.default=we,Object.defineProperty(e,"__esModule",{value:!0})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "app-form-view",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "vue表单组件库",
5
5
  "main": "dist/index.js",
6
6
  "publishConfig": {
package/src/app-index.js CHANGED
@@ -44,7 +44,7 @@ const components = {
44
44
  AppLayoutBlock
45
45
  }
46
46
 
47
- const install = function (Vue) {
47
+ const install = function (Vue, options) {
48
48
  if (install.installed) return
49
49
  install.installed = true
50
50
  if (options.request) {
@@ -136,6 +136,7 @@ export default {
136
136
  const nameArr = item.file.name.split('.');
137
137
  const extRaw = nameArr.length > 1 ? nameArr.pop() : ''
138
138
  const ext = (extRaw || '').toLowerCase()
139
+ console.log(extRaw, ext, 'inputUpload')
139
140
  fileInfo[typeKey] = ext;
140
141
 
141
142
  fileInfo[pathKey] = item.content;
@@ -183,7 +184,7 @@ export default {
183
184
  const rawType = item[typeKey] || ''
184
185
  const itemName = rawName.toLowerCase();
185
186
  const itemType = rawType.toLowerCase();
186
-
187
+ console.log(rawName, rawType, 'rawType')
187
188
  if (itemType) {
188
189
  guessMime = itemType;
189
190
  } else if (itemName) {
@@ -85,6 +85,7 @@ export default {
85
85
  let inputEl = this.$el.querySelector('input, textarea, select, button, a');
86
86
  if (!inputEl) {
87
87
  const tagRaw = this.$el.tagName ? this.$el.tagName : '';
88
+ console.log(tagRaw, 'events')
88
89
  const tagName = tagRaw.toLowerCase();
89
90
  if (['input', 'textarea', 'select', 'button', 'a'].includes(tagName)) {
90
91
  inputEl = this.$el;