34 lines
16 KiB
JavaScript
34 lines
16 KiB
JavaScript
"use weex:vue";
|
|
|
|
if (typeof Promise !== 'undefined' && !Promise.prototype.finally) {
|
|
Promise.prototype.finally = function(callback) {
|
|
const promise = this.constructor
|
|
return this.then(
|
|
value => promise.resolve(callback()).then(() => value),
|
|
reason => promise.resolve(callback()).then(() => {
|
|
throw reason
|
|
})
|
|
)
|
|
}
|
|
};
|
|
|
|
if (typeof uni !== 'undefined' && uni && uni.requireGlobal) {
|
|
const global = uni.requireGlobal()
|
|
ArrayBuffer = global.ArrayBuffer
|
|
Int8Array = global.Int8Array
|
|
Uint8Array = global.Uint8Array
|
|
Uint8ClampedArray = global.Uint8ClampedArray
|
|
Int16Array = global.Int16Array
|
|
Uint16Array = global.Uint16Array
|
|
Int32Array = global.Int32Array
|
|
Uint32Array = global.Uint32Array
|
|
Float32Array = global.Float32Array
|
|
Float64Array = global.Float64Array
|
|
BigInt64Array = global.BigInt64Array
|
|
BigUint64Array = global.BigUint64Array
|
|
};
|
|
|
|
|
|
(()=>{var T=Object.create;var y=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var I=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var L=(e,t,a,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of D(t))!C.call(e,s)&&s!==a&&y(e,s,{get:()=>t[s],enumerable:!(i=x(t,s))||i.enumerable});return e};var N=(e,t,a)=>(a=e!=null?T(M(e)):{},L(t||!e||!e.__esModule?y(a,"default",{value:e,enumerable:!0}):a,e));var A=I((K,v)=>{v.exports=Vue});var _={data(){return{locale:"en",fallbackLocale:"en",localization:{en:{done:"OK",cancel:"Cancel"},zh:{done:"\u5B8C\u6210",cancel:"\u53D6\u6D88"},"zh-hans":{},"zh-hant":{},messages:{}},localizationTemplate:{}}},onLoad(){this.initLocale()},created(){this.initLocale()},methods:{initLocale(){if(this.__initLocale)return;this.__initLocale=!0;let e=(plus.webview.currentWebview().extras||{}).data||{};if(e.messages&&(this.localization.messages=e.messages),e.locale){this.locale=e.locale.toLowerCase();return}let t={chs:"hans",cn:"hans",sg:"hans",cht:"hant",tw:"hant",hk:"hant",mo:"hant"},a=plus.os.language.toLowerCase().split("/")[0].replace("_","-").split("-"),i=a[1];i&&(a[1]=t[i]||i),a.length=a.length>2?2:a.length,this.locale=a.join("-")},localize(e){let t=this.locale,a=t.split("-")[0],i=this.fallbackLocale,s=n=>Object.assign({},this.localization[n],(this.localizationTemplate||{})[n]);return s("messages")[e]||s(t)[e]||s(a)[e]||s(i)[e]||e}}},b={onLoad(){this.initMessage()},methods:{initMessage(){let{from:e,callback:t,runtime:a,data:i={},useGlobalEvent:s}=plus.webview.currentWebview().extras||{};this.__from=e,this.__runtime=a,this.__page=plus.webview.currentWebview().id,this.__useGlobalEvent=s,this.data=JSON.parse(JSON.stringify(i)),plus.key.addEventListener("backbutton",()=>{typeof this.onClose=="function"?this.onClose():plus.webview.currentWebview().close("auto")});let n=this,c=function(o){let u=o.data&&o.data.__message;!u||n.__onMessageCallback&&n.__onMessageCallback(u.data)};if(this.__useGlobalEvent)weex.requireModule("globalEvent").addEventListener("plusMessage",c);else{let o=new BroadcastChannel(this.__page);o.onmessage=c}},postMessage(e={},t=!1){let a=JSON.parse(JSON.stringify({__message:{__page:this.__page,data:e,keep:t}})),i=this.__from;if(this.__runtime==="v8")this.__useGlobalEvent?plus.webview.postMessageToUniNView(a,i):new BroadcastChannel(i).postMessage(a);else{let s=plus.webview.getWebviewById(i);s&&s.evalJS(`__plusMessage&&__plusMessage(${JSON.stringify({data:a})})`)}},onMessage(e){this.__onMessageCallback=e}}};var r=N(A());var d=(e,t)=>{let a=e.__vccOpts||e;for(let[i,s]of t)a[i]=s;return a};var f=e=>e>9?e:"0"+e;function E({date:e=new Date,mode:t="date"}){return t==="time"?f(e.getHours())+":"+f(e.getMinutes()):e.getFullYear()+"-"+f(e.getMonth()+1)+"-"+f(e.getDate())}var V={data(){return{safeAreaInsets:{left:0,right:0,top:0,bottom:0}}},onLoad(){this.initSafeAreaInsets()},created(){this.initSafeAreaInsets()},methods:{initSafeAreaInsets(){if(this.__initSafeAreaInsets)return;this.__initSafeAreaInsets=!0;let e=plus.webview.currentWebview();e.addEventListener("resize",()=>{setTimeout(()=>{this.updateSafeAreaInsets(e)},20)}),this.updateSafeAreaInsets(e)},updateSafeAreaInsets(e){let t=e.getSafeAreaInsets(),a=this.safeAreaInsets;Object.keys(a).forEach(i=>{a[i]=t[i]})}}},O={content:{"":{position:"absolute",top:0,left:0,bottom:0,right:0}},"uni-mask":{"":{position:"absolute",top:0,left:0,bottom:0,right:0,backgroundColor:"rgba(0,0,0,0.4)",opacity:0,transitionProperty:"opacity",transitionDuration:200,transitionTimingFunction:"linear"}},"uni-mask-android":{"":{backgroundColor:"rgba(0,0,0,0.6)"}},"uni-mask-visible":{"":{opacity:1}},"uni-picker":{"":{position:"absolute",left:0,bottom:0,right:0,backgroundColor:"#ffffff",color:"#000000",flexDirection:"column",transform:"translateY(295px)"}},"uni-picker-header":{"":{height:45,borderBottomWidth:0,backgroundColor:"#E6E6E6",fontSize:20}},"uni-picker-action":{"":{position:"absolute",textAlign:"center",top:0,height:45,paddingTop:0,paddingRight:14,paddingBottom:0,paddingLeft:14,fontSize:17,lineHeight:45}},"uni-picker-action-cancel":{"":{left:0,color:"#888888"}},"uni-picker-action-confirm":{"":{right:0,color:"#007aff"}},"uni-picker-content":{"":{flex:1}},"uni-picker-item":{"":{lineHeight:34,textAlign:"center",color:"#000000"}},"@TRANSITION":{"uni-mask":{property:"opacity",duration:200,timingFunction:"linear"}}};function k(){if(this.mode===l.TIME)return"00:00";if(this.mode===l.DATE){let e=new Date().getFullYear()-61;switch(this.fields){case h.YEAR:return e;case h.MONTH:return e+"-01";default:return e+"-01-01"}}return""}function w(){if(this.mode===l.TIME)return"23:59";if(this.mode===l.DATE){let e=new Date().getFullYear()+61;switch(this.fields){case h.YEAR:return e;case h.MONTH:return e+"-12";default:return e+"-12-31"}}return""}function z(e){let t=new Date().getFullYear(),a=t-61,i=t+61;if(e.start){let s=new Date(e.start).getFullYear();!isNaN(s)&&s<a&&(a=s)}if(e.end){let s=new Date(e.start).getFullYear();!isNaN(s)&&s>i&&(i=s)}return{start:a,end:i}}var S=weex.requireModule("animation"),l={SELECTOR:"selector",MULTISELECTOR:"multiSelector",TIME:"time",DATE:"date",REGION:"region"},h={YEAR:"year",MONTH:"month",DAY:"day"},Y={name:"Picker",mixins:[_,V],props:{pageId:{type:Number,default:0},range:{type:Array,default(){return[]}},rangeKey:{type:String,default:""},value:{type:[Number,String,Array],default:0},mode:{type:String,default:l.SELECTOR},fields:{type:String,default:h.DAY},start:{type:String,default:k},end:{type:String,default:w},disabled:{type:[Boolean,String],default:!1},visible:{type:Boolean,default:!1}},data(){return{valueSync:null,timeArray:[],dateArray:[],valueArray:[],oldValueArray:[],fontSize:16,height:261,android:weex.config.env.platform.toLowerCase()==="android"}},computed:{rangeArray(){var e=this.range;switch(this.mode){case l.SELECTOR:return[e];case l.MULTISELECTOR:return e;case l.TIME:return this.timeArray;case l.DATE:{let t=this.dateArray;switch(this.fields){case h.YEAR:return[t[0]];case h.MONTH:return[t[0],t[1]];default:return[t[0],t[1],t[2]]}}}return[]},startArray(){return this._getDateValueArray(this.start,k.bind(this)())},endArray(){return this._getDateValueArray(this.end,w.bind(this)())},textMaxLength(){return Math.floor(Math.min(weex.config.env.deviceWidth,weex.config.env.deviceHeight)/(this.fontSize*weex.config.env.scale+1)/this.rangeArray.length)}},watch:{value(){this._setValueSync()},mode(){this._setValueSync()},range(){this._setValueSync()},valueSync(){this._setValueArray()},valueArray(e){if(this.mode===l.TIME||this.mode===l.DATE){let t=this.mode===l.TIME?this._getTimeValue:this._getDateValue,a=this.valueArray,i=this.startArray,s=this.endArray;if(this.mode===l.DATE){let n=this.dateArray,c=n[2].length,o=Number(n[2][a[2]])||1,u=new Date(`${n[0][a[0]]}/${n[1][a[1]]}/${o}`).getDate();u<o&&(a[2]-=u+c-o)}t(a)<t(i)?this._cloneArray(a,i):t(a)>t(s)&&this._cloneArray(a,s)}e.forEach((t,a)=>{t!==this.oldValueArray[a]&&(this.oldValueArray[a]=t,this.mode===l.MULTISELECTOR&&this.$emit("columnchange",{column:a,value:t}))})},visible(e){e?setTimeout(()=>{S.transition(this.$refs.picker,{styles:{transform:"translateY(0)"},duration:200})},20):S.transition(this.$refs.picker,{styles:{transform:`translateY(${283+this.safeAreaInsets.bottom}px)`},duration:200})}},created(){this._createTime(),this._createDate(),this._setValueSync()},methods:{getTexts(e,t){let a=this.textMaxLength;return e.map(i=>{let s=String(typeof i=="object"?i[this.rangeKey]||"":this._l10nItem(i,t));if(a>0&&s.length>a){let n=0,c=0;for(let o=0;o<s.length;o++){let u=s.charCodeAt(o);if(u>127||u===94?n+=1:n+=.65,n<=a-1&&(c=o),n>=a)return o===s.length-1?s:s.substr(0,c+1)+"\u2026"}}return s||" "}).join(`
|
|
`)},_createTime(){var e=[],t=[];e.splice(0,e.length);for(let a=0;a<24;a++)e.push((a<10?"0":"")+a);t.splice(0,t.length);for(let a=0;a<60;a++)t.push((a<10?"0":"")+a);this.timeArray.push(e,t)},_createDate(){var e=[],t=z(this);for(let s=t.start,n=t.end;s<=n;s++)e.push(String(s));var a=[];for(let s=1;s<=12;s++)a.push((s<10?"0":"")+s);var i=[];for(let s=1;s<=31;s++)i.push((s<10?"0":"")+s);this.dateArray.push(e,a,i)},_getTimeValue(e){return e[0]*60+e[1]},_getDateValue(e){return e[0]*31*12+(e[1]||0)*31+(e[2]||0)},_cloneArray(e,t){for(let a=0;a<e.length&&a<t.length;a++)e[a]=t[a]},_setValueSync(){let e=this.value;switch(this.mode){case l.MULTISELECTOR:Array.isArray(e)||(e=[]),Array.isArray(this.valueSync)||(this.valueSync=[]);let t=this.valueSync.length=Math.max(e.length,this.range.length);for(let a=0;a<t;a++){let i=Number(e[a]),s=Number(this.valueSync[a]),n=isNaN(i)?isNaN(s)?0:s:i,c=this.range[a]?this.range[a].length-1:0;this.valueSync.splice(a,1,n<0||n>c?0:n)}break;case l.TIME:case l.DATE:this.valueSync=String(e);break;default:{let a=Number(e);this.valueSync=a<0?0:a;break}}},_setValueArray(){var e=this.valueSync,t;switch(this.mode){case l.MULTISELECTOR:t=[...e];break;case l.TIME:t=this._getDateValueArray(e,E({mode:l.TIME}));break;case l.DATE:t=this._getDateValueArray(e,E({mode:l.DATE}));break;default:t=[e];break}this.oldValueArray=[...t],this.valueArray=[...t]},_getValue(){var e=this.valueArray;switch(this.mode){case l.SELECTOR:return e[0];case l.MULTISELECTOR:return e.map(t=>t);case l.TIME:return this.valueArray.map((t,a)=>this.timeArray[a][t]).join(":");case l.DATE:return this.valueArray.map((t,a)=>this.dateArray[a][t]).join("-")}},_getDateValueArray(e,t){let a=this.mode===l.DATE?"-":":",i=this.mode===l.DATE?this.dateArray:this.timeArray,s=3;switch(this.fields){case h.YEAR:s=1;break;case h.MONTH:s=2;break}let n=String(e).split(a),c=[];for(let o=0;o<s;o++){let u=n[o];c.push(i[o].indexOf(u))}return c.indexOf(-1)>=0&&(c=t?this._getDateValueArray(t):c.map(()=>0)),c},_change(){this.$emit("change",{value:this._getValue()})},_cancel(){this.$emit("cancel")},_pickerViewChange(e){this.valueArray=this._l10nColumn(e.detail.value,!0)},_l10nColumn(e,t){if(this.mode===l.DATE){let a=this.locale;if(!a.startsWith("zh"))switch(this.fields){case h.YEAR:return e;case h.MONTH:return[e[1],e[0]];default:switch(a){case"es":case"fr":return[e[2],e[1],e[0]];default:return t?[e[2],e[0],e[1]]:[e[1],e[2],e[0]]}}}return e},_l10nItem(e,t){if(this.mode===l.DATE){let a=this.locale;if(a.startsWith("zh"))return e+["\u5E74","\u6708","\u65E5"][t];if(this.fields!==h.YEAR&&t===(this.fields!==h.MONTH&&(a==="es"||a==="fr")?1:0)){let i;switch(a){case"es":i=["enero","febrero","marzo","abril","mayo","junio","\u200B\u200Bjulio","agosto","septiembre","octubre","noviembre","diciembre"];break;case"fr":i=["janvier","f\xE9vrier","mars","avril","mai","juin","juillet","ao\xFBt","septembre","octobre","novembre","d\xE9cembre"];break;default:i=["January","February","March","April","May","June","July","August","September","October","November","December"];break}return i[Number(e)-1]}}return e}}};function R(e,t,a,i,s,n){let c=(0,r.resolveComponent)("picker-view-column"),o=(0,r.resolveComponent)("picker-view");return(0,r.openBlock)(),(0,r.createElementBlock)("div",{class:"content"},[(0,r.createElementVNode)("div",{ref:"mask",style:(0,r.normalizeStyle)({opacity:a.visible?1:0,"background-color":s.android?"rgba(0, 0, 0, 0.6)":"rgba(0, 0, 0, 0.4)"}),class:"uni-mask",onClick:t[0]||(t[0]=(...u)=>n._cancel&&n._cancel(...u))},null,4),(0,r.createElementVNode)("div",{style:(0,r.normalizeStyle)(`padding-bottom:${e.safeAreaInsets.bottom}px;height:${s.height+e.safeAreaInsets.bottom}px;`),ref:"picker",class:"uni-picker"},[(0,r.createElementVNode)("div",{class:"uni-picker-header"},[(0,r.createElementVNode)("u-text",{style:(0,r.normalizeStyle)(`left:${e.safeAreaInsets.left}px`),class:"uni-picker-action uni-picker-action-cancel",onClick:t[1]||(t[1]=(...u)=>n._cancel&&n._cancel(...u))},(0,r.toDisplayString)(e.localize("cancel")),5),(0,r.createElementVNode)("u-text",{style:(0,r.normalizeStyle)(`right:${e.safeAreaInsets.right}px`),class:"uni-picker-action uni-picker-action-confirm",onClick:t[2]||(t[2]=(...u)=>n._change&&n._change(...u))},(0,r.toDisplayString)(e.localize("done")),5)]),a.visible?((0,r.openBlock)(),(0,r.createBlock)(o,{key:0,style:(0,r.normalizeStyle)(`margin-left:${e.safeAreaInsets.left}px`),height:"216","indicator-style":"height: 34px;border-color:#C8C9C9;border-top-width:0.5px;border-bottom-width:0.5px;",value:n._l10nColumn(s.valueArray),class:"uni-picker-content",onChange:n._pickerViewChange},{default:(0,r.withCtx)(()=>[((0,r.openBlock)(!0),(0,r.createElementBlock)(r.Fragment,null,(0,r.renderList)(n._l10nColumn(n.rangeArray),(u,p)=>((0,r.openBlock)(),(0,r.createBlock)(c,{length:u.length,key:p},{default:(0,r.withCtx)(()=>[(0,r.createCommentVNode)(" iOS\u6E32\u67D3\u901F\u5EA6\u6709\u95EE\u9898\u4F7F\u7528\u5355\u4E2Atext\u4F18\u5316 "),(0,r.createElementVNode)("u-text",{class:"uni-picker-item",style:(0,r.normalizeStyle)({fontSize:s.fontSize+"px","line-height":"34px","text-align":"center",color:"#000"})},(0,r.toDisplayString)(n.getTexts(u,p)),5),(0,r.createCommentVNode)(` <text v-for="(item,index) in range" :key="index" class="uni-picker-item uni-picker-item-line" :style="{fontSize: fontSize + 'px'}">{{ typeof item==='object'?item[rangeKey]||'':_l10nItem(item) }}</text> `)]),_:2},1032,["length"]))),128))]),_:1},8,["style","value","onChange"])):(0,r.createCommentVNode)("v-if",!0)],4)])}var B=d(Y,[["render",R],["styles",[O]]]),F={page:{"":{flex:1}}},j={mixins:[b],components:{picker:B},data(){return{range:[],rangeKey:"",value:0,mode:"selector",fields:"day",start:"",end:"",disabled:!1,visible:!1}},onLoad(){this.data===null?this.postMessage({event:"created"},!0):this.showPicker(this.data),this.onMessage(e=>{this.showPicker(e)})},onReady(){this.$nextTick(()=>{this.visible=!0})},methods:{showPicker(e={}){let t=e.column;for(let a in e)a!=="column"&&(typeof t=="number"?this.$set(this.$data[a],t,e[a]):this.$data[a]=e[a])},close(e,{value:t=-1}={}){this.visible=!1,setTimeout(()=>{this.postMessage({event:e,value:t})},210)},onClose(){this.close("cancel")},columnchange({column:e,value:t}){this.$set(this.value,e,t),this.postMessage({event:"columnchange",column:e,value:t},!0)}}};function H(e,t,a,i,s,n){let c=(0,r.resolveComponent)("picker");return(0,r.openBlock)(),(0,r.createElementBlock)("scroll-view",{scrollY:!0,showScrollbar:!0,enableBackToTop:!0,bubble:"true",style:{flexDirection:"column"}},[(0,r.createElementVNode)("view",{class:"page"},[(0,r.createVNode)(c,{range:s.range,rangeKey:s.rangeKey,value:s.value,mode:s.mode,fields:s.fields,start:s.start,end:s.end,disabled:s.disabled,visible:s.visible,onChange:t[0]||(t[0]=o=>n.close("change",o)),onCancel:t[1]||(t[1]=o=>n.close("cancel",o)),onColumnchange:n.columnchange},null,8,["range","rangeKey","value","mode","fields","start","end","disabled","visible","onColumnchange"])])])}var g=d(j,[["render",H],["styles",[F]]]);var m=plus.webview.currentWebview();if(m){let e=parseInt(m.id),t="template/__uniapppicker",a={};try{a=JSON.parse(m.__query__)}catch(s){}g.mpType="page";let i=Vue.createPageApp(g,{$store:getApp({allowDefault:!0}).$store,__pageId:e,__pagePath:t,__pageQuery:a});i.provide("__globalStyles",Vue.useCssStyles([...__uniConfig.styles,...g.styles||[]])),i.mount("#root")}})();
|