From fcc57faab671541bd543f82f5f84096bda59f126 Mon Sep 17 00:00:00 2001 From: Juzi Date: Wed, 24 Nov 2021 22:29:21 +0800 Subject: [PATCH] build: Travis CI automatic compilation --- dist/behaviors/countdown.js | 2 +- dist/behaviors/rules.js | 2 +- dist/calendar/components/mounth/index.js | 2 +- dist/calendar/index.js | 2 +- dist/checkbox-group/index.js | 2 +- dist/image-picker/index.js | 2 +- dist/input/index.wxml | 2 +- dist/mask/index.js | 2 +- dist/message/index.wxss | 2 +- dist/tab-bar/index.js | 2 +- examples/dist/behaviors/countdown.js | 2 +- examples/dist/behaviors/rules.js | 2 +- examples/dist/calendar/components/mounth/index.js | 8 +++----- examples/dist/calendar/index.js | 14 ++++++-------- examples/dist/checkbox-group/index.js | 6 +++--- examples/dist/image-picker/index.js | 2 +- examples/dist/input/index.wxml | 2 +- examples/dist/mask/index.js | 2 +- examples/dist/message/index.wxss | 2 +- examples/dist/tab-bar/index.js | 5 ----- 20 files changed, 28 insertions(+), 37 deletions(-) diff --git a/dist/behaviors/countdown.js b/dist/behaviors/countdown.js index b5efbeb9..80901af3 100644 --- a/dist/behaviors/countdown.js +++ b/dist/behaviors/countdown.js @@ -1 +1 @@ -export default Behavior({behaviors:[],properties:{time:{type:Date,value:(new Date).getTime()+864e5,observer:function(t,e){t&&!e&&this.getLatestTime()}},status:{type:Boolean,value:!0,observer:function(t){t?this.init():t||clearInterval(this.data.timer)}},timeType:{type:String,value:"datetime"},format:{type:String,value:"{%d}天{%h}时{%m}分{%s}秒"},isZeroPadd:{type:Boolean,value:!0},countdownType:{type:String,value:"normal"},isClearInterval:{type:Boolean,value:!0}},data:{initAddTime:0,timer:null,date:[]},ready:function(){this.getLatestTime()},detached:function(){this.data.isClearInterval&&clearInterval(this.data.timer)},pageLifetimes:{hide(){this.data.isClearInterval&&clearInterval(this.data.timer)},show(){this.data.isClearInterval&&this.getLatestTime()}},methods:{zeroPadding:t=>(t=t.toString())[1]?t:"0"+t,init(){clearInterval(this.data.timer);const t=setTimeout(()=>{this.getLatestTime.call(this)},1e3);this.setData({timer:t})},getLatestTime(){let{time:t,status:e,timeType:i,initAddTime:a,countdownType:n}=this.data,s=t;if("normal"===n){if("second"!==i&&(s="string"==typeof t?s.replace(/-/g,"/"):s,s=Math.ceil((new Date(s).getTime()-(new Date).getTime())/1e3)),s<0&&"second"!==i)return this._getTimeValue(0),void this.CountdownEnd();s-a>0?this.getLatestForCountDown(s):s-a<0?this.getLatestForAddTime(s):s-a==0&&(a<=0&&this._getTimeValue(s),this.CountdownEnd()),e&&s-a!=0&&this.init.call(this)}else"anniversary"===n?"second"===i?console.error(`countdownType为${n}类型时,不可设置timeType值为second`):(s="string"==typeof t?s.replace(/-/g,"/"):s,s=Math.ceil(((new Date).getTime()-new Date(s).getTime())/1e3),s>=0?(this.getLatestForCountDown(s),this.init.call(this)):console.error("time传值错误")):console.error("错误的countdownType类型")},getLatestForAddTime(t){let{initAddTime:e}=this.data;e!==Math.abs(t)&&(e++,this._getTimeValue(e),this.setData({initAddTime:e}))},getLatestForCountDown(t){this._getTimeValue(t),this.setData({time:"second"===this.data.timeType?--t:this.data.time})},_getTimeValue(t){const{format:e}=this.data,i=[],a=e.split(/(\{.*?\})/);let n=t;return[{key:"{%d}",type:"day",count:86400},{key:"{%h}",type:"hour",count:3600},{key:"{%m}",type:"minute",count:60},{key:"{%s}",type:"second",count:1}].forEach(t=>{const e=this._findTimeName(a,t.key);if(-1===e)return;const s=a[e],o={type:t.type,name:s,value:parseInt(n/t.count)};this.data.isZeroPadd&&(o.value=this.zeroPadding(o.value)),n%=t.count,i.push(o)}),this.setData({date:i}),i},_findTimeName(t,e){const i=t.indexOf(e);return-1===i?-1:i+1},CountdownEnd(){this.triggerEvent("linend",{})}}}); \ No newline at end of file +export default Behavior({behaviors:[],properties:{time:{type:Object,value:(new Date).getTime()+864e5,observer:function(t,e){t&&!e&&this.getLatestTime()}},status:{type:Boolean,value:!0,observer:function(t){t?this.init():t||clearInterval(this.data.timer)}},timeType:{type:String,value:"datetime"},format:{type:String,value:"{%d}天{%h}时{%m}分{%s}秒"},isZeroPadd:{type:Boolean,value:!0},countdownType:{type:String,value:"normal"},isClearInterval:{type:Boolean,value:!0}},data:{initAddTime:0,timer:null,date:[]},ready:function(){this.getLatestTime()},detached:function(){this.data.isClearInterval&&clearInterval(this.data.timer)},pageLifetimes:{hide(){this.data.isClearInterval&&clearInterval(this.data.timer)},show(){this.data.isClearInterval&&this.getLatestTime()}},methods:{zeroPadding:t=>(t=t.toString())[1]?t:"0"+t,init(){clearInterval(this.data.timer);const t=setTimeout(()=>{this.getLatestTime.call(this)},1e3);this.setData({timer:t})},getLatestTime(){let{time:t,status:e,timeType:i,initAddTime:a,countdownType:n}=this.data,s=t;if("normal"===n){if("second"!==i&&(s="string"==typeof t?s.replace(/-/g,"/"):s,s=Math.ceil((new Date(s).getTime()-(new Date).getTime())/1e3)),s<0&&"second"!==i)return this._getTimeValue(0),void this.CountdownEnd();s-a>0?this.getLatestForCountDown(s):s-a<0?this.getLatestForAddTime(s):s-a==0&&(a<=0&&this._getTimeValue(s),this.CountdownEnd()),e&&s-a!=0&&this.init.call(this)}else"anniversary"===n?"second"===i?console.error(`countdownType为${n}类型时,不可设置timeType值为second`):(s="string"==typeof t?s.replace(/-/g,"/"):s,s=Math.ceil(((new Date).getTime()-new Date(s).getTime())/1e3),s>=0?(this.getLatestForCountDown(s),this.init.call(this)):console.error("time传值错误")):console.error("错误的countdownType类型")},getLatestForAddTime(t){let{initAddTime:e}=this.data;e!==Math.abs(t)&&(e++,this._getTimeValue(e),this.setData({initAddTime:e}))},getLatestForCountDown(t){this._getTimeValue(t),this.setData({time:"second"===this.data.timeType?--t:this.data.time})},_getTimeValue(t){const{format:e}=this.data,i=[],a=e.split(/(\{.*?\})/);let n=t;return[{key:"{%d}",type:"day",count:86400},{key:"{%h}",type:"hour",count:3600},{key:"{%m}",type:"minute",count:60},{key:"{%s}",type:"second",count:1}].forEach(t=>{const e=this._findTimeName(a,t.key);if(-1===e)return;const s=a[e],o={type:t.type,name:s,value:parseInt(n/t.count)};this.data.isZeroPadd&&(o.value=this.zeroPadding(o.value)),n%=t.count,i.push(o)}),this.setData({date:i}),i},_findTimeName(t,e){const i=t.indexOf(e);return-1===i?-1:i+1},CountdownEnd(){this.triggerEvent("linend",{})}}}); \ No newline at end of file diff --git a/dist/behaviors/rules.js b/dist/behaviors/rules.js index 200caf39..1639a8f1 100644 --- a/dist/behaviors/rules.js +++ b/dist/behaviors/rules.js @@ -1 +1 @@ -import Schema from"../common/async-validator/index";import validator from"../behaviors/validator";export default Behavior({behaviors:[validator],properties:{rules:{type:[Object,Array],value:[]},tipType:{type:String,value:"toast",options:["toast","message","text"]}},data:{schema:"",tipFun:{message:"showMessage",toast:"showToast"},tipContent:{message:"content",toast:"title"},errorText:"",errors:[]},methods:{initRules(){const{rules:t}=this.data;t&&("[object Object]"===Object.prototype.toString.call(t)&&(this.data.rules=[t]),this.data.rules.forEach(t=>{t.trigger?"string"!=typeof t.trigger||(t.trigger=[t.trigger]):t.trigger=[]}))},getNeedValidateRule(t){const e=this.data.name,{rules:a}=this.data;if(!a)return;const r=t?a.filter(e=>e.trigger.indexOf(t)>-1):a,s=new Schema({[e]:r});return this.setData({schema:s}),r},validatorData(t,e){const{tipType:a,tipFun:r,tipContent:s}=this.data;this.getNeedValidateRule(e)&&(Object.getOwnPropertyNames(t).forEach(e=>{""===t[e]&&(t[e]=void 0)}),this.data.schema.validate(t,t=>{if(this.setData({errors:t||[]}),this.triggerEvent("linvalidate",{errors:t,isError:!!t}),t&&a){const e=r[a],i=s[a];return"text"===a?(this.setData({errorText:t[0].message}),t):wx.lin&&wx.lin[e]?(wx.lin[e]&&wx.lin[e]({[i]:t[0].message,duration:1500,mask:!1}),t):(wx.showToast({icon:"none",title:`请在页面内引入${a}组件`}),t)}!t&&a&&this.setData({errorText:""})}))}}}); \ No newline at end of file +import Schema from"../common/async-validator/index";import validator from"../behaviors/validator";export default Behavior({behaviors:[validator],properties:{rules:{optionalTypes:[Object,Array],value:[]},tipType:{type:String,value:"toast",options:["toast","message","text"]}},data:{schema:"",tipFun:{message:"showMessage",toast:"showToast"},tipContent:{message:"content",toast:"title"},errorText:"",errors:[]},methods:{initRules(){const{rules:t}=this.data;t&&("[object Object]"===Object.prototype.toString.call(t)&&(this.data.rules=[t]),this.data.rules.forEach(t=>{t.trigger?"string"!=typeof t.trigger||(t.trigger=[t.trigger]):t.trigger=[]}))},getNeedValidateRule(t){const e=this.data.name,{rules:a}=this.data;if(!a)return;const r=t?a.filter(e=>e.trigger.indexOf(t)>-1):a,s=new Schema({[e]:r});return this.setData({schema:s}),r},validatorData(t,e){const{tipType:a,tipFun:r,tipContent:s}=this.data;this.getNeedValidateRule(e)&&(Object.getOwnPropertyNames(t).forEach(e=>{""===t[e]&&(t[e]=void 0)}),this.data.schema.validate(t,t=>{if(this.setData({errors:t||[]}),this.triggerEvent("linvalidate",{errors:t,isError:!!t}),t&&a){const e=r[a],i=s[a];return"text"===a?(this.setData({errorText:t[0].message}),t):wx.lin&&wx.lin[e]?(wx.lin[e]&&wx.lin[e]({[i]:t[0].message,duration:1500,mask:!1}),t):(wx.showToast({icon:"none",title:`请在页面内引入${a}组件`}),t)}!t&&a&&this.setData({errorText:""})}))}}}); \ No newline at end of file diff --git a/dist/calendar/components/mounth/index.js b/dist/calendar/components/mounth/index.js index 6515d797..67ae3645 100644 --- a/dist/calendar/components/mounth/index.js +++ b/dist/calendar/components/mounth/index.js @@ -1 +1 @@ -import{compareDay,getMonthEndDay}from"../../util";import*as config from"../../config";Component({data:{days:[]},properties:{minDate:{type:[Date,String,null]},maxDate:{type:[Date,String,null]},formatter:{type:null,observer:"setDays"},date:{type:null,observer:"setDays"},currentDate:{type:[null,Array],observer(){this.setDays()}},type:{type:String,observer:"setDays"},showMonthTitle:Boolean,color:{type:String,value:""}},methods:{onClick(t){const{item:e}=t.currentTarget.dataset;"disabled"!==e.type&&"empty"!==e.type&&this.triggerEvent("clickDay",e)},debounce(t){let e;return()=>{let a=this,r=arguments;e&&clearTimeout(e),e=setTimeout((function(){t.apply(a,r)}),300)}},setDays(){this.debounce(this.setDay)()},setDay(){let t=[];const e=new Date(this.data.date),a=e.getFullYear(),r=e.getMonth(),n=new Date(a,r,1).getDay(),o=getMonthEndDay(a,r+1);for(let e=1;e<=o;e++){const n=new Date(a,r,e).getTime(),o=this.getDayType(n);let s={date:n,type:o,text:e,bottomInfo:this.getBottomInfo(o),topInfo:""};this.data.formatter&&(s=this.data.formatter(s)),t.push(s)}for(let e=0;e0===compareDay(e,t))},getMultipleDayType(t){const{currentDate:e}=this.data;return Array.isArray(e)&&this.isDateInCurrent(t)?"selected":""},getRangeDayType(t){const{currentDate:e}=this.data;if(!Array.isArray(e))return;const[a,r]=e;if(!a)return;const n=compareDay(t,a);if(!r)return 0===n?"start":"";const o=compareDay(t,r);return 0===n?"start":0===o?"end":n>0&&o<0?"middle":void 0},getDayType(t){const{type:e,minDate:a,maxDate:r,currentDate:n}=this.data;return compareDay(t,a)<0||compareDay(t,r)>0?"disabled":e===config.TYPE_SINGLE?0===compareDay(t,n)?"selected":"":e===config.TYPE_MULTIPLE?this.getMultipleDayType(t):e===config.TYPE_RANGE?this.getRangeDayType(t):void 0},getBottomInfo(t){return this.data.type===config.TYPE_RANGE?"start"===t?"开始":"end"===t?"结束":"":""}}}); \ No newline at end of file +import{compareDay,getMonthEndDay}from"../../util";import*as config from"../../config";Component({data:{days:[]},properties:{minDate:{optionalTypes:[Object,String]},maxDate:{optionalTypes:[Object,String]},formatter:{type:null,observer:"setDays"},date:{type:null,observer:"setDays"},currentDate:{optionalTypes:[Array],observer(){this.setDays()}},type:{type:String,observer:"setDays"},showMonthTitle:Boolean,color:{type:String,value:""}},methods:{onClick(t){const{item:e}=t.currentTarget.dataset;"disabled"!==e.type&&"empty"!==e.type&&this.triggerEvent("clickDay",e)},debounce(t){let e;return()=>{let a=this,r=arguments;e&&clearTimeout(e),e=setTimeout((function(){t.apply(a,r)}),300)}},setDays(){this.debounce(this.setDay)()},setDay(){let t=[];const e=new Date(this.data.date),a=e.getFullYear(),r=e.getMonth(),o=new Date(a,r,1).getDay(),n=getMonthEndDay(a,r+1);for(let e=1;e<=n;e++){const o=new Date(a,r,e).getTime(),n=this.getDayType(o);let s={date:o,type:n,text:e,bottomInfo:this.getBottomInfo(n),topInfo:""};this.data.formatter&&(s=this.data.formatter(s)),t.push(s)}for(let e=0;e0===compareDay(e,t))},getMultipleDayType(t){const{currentDate:e}=this.data;return Array.isArray(e)&&this.isDateInCurrent(t)?"selected":""},getRangeDayType(t){const{currentDate:e}=this.data;if(!Array.isArray(e))return;const[a,r]=e;if(!a)return;const o=compareDay(t,a);if(!r)return 0===o?"start":"";const n=compareDay(t,r);return 0===o?"start":0===n?"end":o>0&&n<0?"middle":void 0},getDayType(t){const{type:e,minDate:a,maxDate:r,currentDate:o}=this.data;return compareDay(t,a)<0||compareDay(t,r)>0?"disabled":e===config.TYPE_SINGLE?0===compareDay(t,o)?"selected":"":e===config.TYPE_MULTIPLE?this.getMultipleDayType(t):e===config.TYPE_RANGE?this.getRangeDayType(t):void 0},getBottomInfo(t){return this.data.type===config.TYPE_RANGE?"start"===t?"开始":"end"===t?"结束":"":""}}}); \ No newline at end of file diff --git a/dist/calendar/index.js b/dist/calendar/index.js index 75549da5..dc16dda6 100644 --- a/dist/calendar/index.js +++ b/dist/calendar/index.js @@ -1 +1 @@ -import eventBus from"../core/utils/event-bus.js";import validator from"../behaviors/validator";import rules from"../behaviors/rules";import*as config from"./config";import formatFlags from"./dete";import{getDayByOffset,getDate,compareDay,calcDateNum,copyDates,getTime,formatMonthTitle,compareMonth,getMonths}from"./util";Component({externalClasses:["l-class"],behaviors:["wx://form-field",validator,rules],properties:{show:{type:Boolean,value:!1,observer(t){t&&(this.initRect(),this.scrollIntoView())}},type:{type:String,value:config.TYPE_SINGLE,options:[config.TYPE_SINGLE,config.TYPE_MULTIPLE,config.TYPE_RANGE],observer(){this.setData({currentDate:this.initCurrentDate()})}},color:{type:String,value:""},defaultDate:{type:[String,Number,Date,Array],value:"",observer(){this.setData({currentDate:this.initCurrentDate()})}},format:{type:String,value:"timestamp"},formatter:{type:[Function,null],value:null},minDate:{type:[String,Number,null],value:Date.now()},maxDate:{type:[String,Number,null],value:new Date((new Date).getFullYear(),(new Date).getMonth()+6,(new Date).getDate()).getTime()},minSelect:{type:[Number,null],value:null},maxSelect:{type:[Number,null],value:null},allowSameDay:Boolean,showConfirm:{type:Boolean,value:!0},confirmText:{type:String,value:"确认"},maxLimitMessage:{type:String},minLimitMessage:{type:String},showTitle:{type:Boolean,value:!0},showSubtitle:{type:Boolean,value:!0},title:{type:String,value:"日期选择"}},lifetimes:{attached(){this.setData({currentDate:this.initCurrentDate()})},ready(){this.data.show&&(this.initRect(),this.scrollIntoView())}},data:{currentDate:null,types:config,subTitle:"",scrollIntoViewIndex:""},methods:{clickDay(t){const{type:e,currentDate:a,maxLimitMessage:i,maxSelect:r,allowSameDay:n}=this.data,{date:s}=t.detail;if(e===config.TYPE_SINGLE&&(this.setData({currentDate:getTime(s)}),this.triggerEvent("linclickday",copyDates(s)),this.triggerEvent("linselect",copyDates(s))),e===config.TYPE_MULTIPLE){let t=null;if(a.some((e,a)=>{const i=0===compareDay(e,s);return i&&(t=a),i}))a.splice(t,1),this.setData({currentDate:getTime(a)}),this.triggerEvent("linunselect",copyDates(a));else{if(r&&a.length>=r)return wx.lin.showToast({title:i||`选择天数不能超过 ${r} 天`}),void this.triggerEvent("linclickday",copyDates(s));this.setData({currentDate:getTime([...a,s])}),this.triggerEvent("linselect",copyDates([...a,s]))}this.triggerEvent("linclickday",copyDates(s))}if(e===config.TYPE_RANGE){const[t,e]=a;if(t&&!e){const e=compareDay(s,t);1===e?this.checkSelectRange([t,s])&&(this.setData({currentDate:getTime([t,s])}),this.triggerEvent("linselect",copyDates([t,s]))):-1===e?this.setData({currentDate:getTime([s,null])}):n&&this.setData({currentDate:getTime([s,s])})}else this.setData({currentDate:getTime([s,null])})}},checkSelectRange(t){const{maxSelect:e,maxLimitMessage:a,minSelect:i,minLimitMessage:r}=this.data;return e&&calcDateNum(t)>e?(wx.lin.showToast({title:a||`选择天数不能超过 ${e} 天`}),!1):!(i&&calcDateNum(t)1===compareDay(t,e)&&-1===compareDay(t,i)):-1===compareDay(a,e)?[e]:1===compareDay(a,i)?[i]:[e]:[];if(t===config.TYPE_RANGE){if(r){let[t=e,r]=a;return-1!==compareDay(t,e)&&-1===compareDay(t,i)||(t=e),r||(r=getDayByOffset(getDate(t),1).getTime()),1!==compareDay(r,i)&&-1!==compareDay(r,e)||(r=getDayByOffset(getDate(t),1).getTime()),[t,r]}return[e,getDayByOffset(getDate(e),1).getTime()]}},initRect(){null!==!this.contentObserver&&void 0!==this.contentObserver&&this.contentObserver.disconnect();const t=this.createIntersectionObserver({thresholds:[0,.1,.9,1],observeAll:!0});this.contentObserver=t,t.relativeTo(".calendar-body-wrap"),t.observe(".month",t=>{t.boundingClientRect.top<=t.relativeRect.top&&this.setData({subTitle:formatMonthTitle(t.dataset.date)})})},scrollIntoView(){setTimeout(()=>{const{currentDate:t,type:e,show:a,minDate:i,maxDate:r}=this.data,n="single"===e?t:t[0];if(!n||!a)return;getMonths(i,r).some((t,e)=>0===compareMonth(t,n)&&(this.setData({scrollIntoViewIndex:"month"+e}),!0))},100)},closePicker(){this.setData({show:!1})},onClickConfirm(){const{format:t,type:e,currentDate:a}=this.data;eventBus.emit("lin-form-blur-"+this.id,this.id);let i=null;i="single"===e?"timestamp"!==t?formatFlags.format("yyyy-MM-dd",a):a:a.map(e=>"timestamp"!==t?formatFlags.format("yyyy-MM-dd",e):e),this.triggerEvent("linconfirm",i)},getValues(){return this.data.currentDate},reset(){this.setData({currentDate:null})}}}); \ No newline at end of file +import eventBus from"../core/utils/event-bus.js";import validator from"../behaviors/validator";import rules from"../behaviors/rules";import*as config from"./config";import formatFlags from"./dete";import{getDayByOffset,getDate,compareDay,calcDateNum,copyDates,getTime,formatMonthTitle,compareMonth,getMonths}from"./util";Component({externalClasses:["l-class"],behaviors:["wx://form-field",validator,rules],properties:{show:{type:Boolean,value:!1,observer(t){t&&(this.initRect(),this.scrollIntoView())}},type:{type:String,value:config.TYPE_SINGLE,options:[config.TYPE_SINGLE,config.TYPE_MULTIPLE,config.TYPE_RANGE],observer(){this.setData({currentDate:this.initCurrentDate()})}},color:{type:String,value:""},defaultDate:{optionalTypes:[String,Number,Date,Array],observer(){this.setData({currentDate:this.initCurrentDate()})}},format:{type:String,value:"timestamp"},formatter:{type:Object,value:null},minDate:{optionalTypes:[String,Number],value:Date.now()},maxDate:{optionalTypes:[String,Number],value:new Date((new Date).getFullYear(),(new Date).getMonth()+6,(new Date).getDate()).getTime()},minSelect:{type:Number,value:null},maxSelect:{type:Number,value:null},allowSameDay:Boolean,showConfirm:{type:Boolean,value:!0},confirmText:{type:String,value:"确认"},maxLimitMessage:{type:String},minLimitMessage:{type:String},showTitle:{type:Boolean,value:!0},showSubtitle:{type:Boolean,value:!0},title:{type:String,value:"日期选择"}},lifetimes:{attached(){this.setData({currentDate:this.initCurrentDate()})},ready(){this.data.show&&(this.initRect(),this.scrollIntoView())}},data:{currentDate:null,types:config,subTitle:"",scrollIntoViewIndex:""},methods:{clickDay(t){const{type:e,currentDate:a,maxLimitMessage:i,maxSelect:r,allowSameDay:s}=this.data,{date:n}=t.detail;if(e===config.TYPE_SINGLE&&(this.setData({currentDate:getTime(n)}),this.triggerEvent("linclickday",copyDates(n)),this.triggerEvent("linselect",copyDates(n))),e===config.TYPE_MULTIPLE){let t=null;if(a.some((e,a)=>{const i=0===compareDay(e,n);return i&&(t=a),i}))a.splice(t,1),this.setData({currentDate:getTime(a)}),this.triggerEvent("linunselect",copyDates(a));else{if(r&&a.length>=r)return wx.lin.showToast({title:i||`选择天数不能超过 ${r} 天`}),void this.triggerEvent("linclickday",copyDates(n));this.setData({currentDate:getTime([...a,n])}),this.triggerEvent("linselect",copyDates([...a,n]))}this.triggerEvent("linclickday",copyDates(n))}if(e===config.TYPE_RANGE){const[t,e]=a;if(t&&!e){const e=compareDay(n,t);1===e?this.checkSelectRange([t,n])&&(this.setData({currentDate:getTime([t,n])}),this.triggerEvent("linselect",copyDates([t,n]))):-1===e?this.setData({currentDate:getTime([n,null])}):s&&this.setData({currentDate:getTime([n,n])})}else this.setData({currentDate:getTime([n,null])})}},checkSelectRange(t){const{maxSelect:e,maxLimitMessage:a,minSelect:i,minLimitMessage:r}=this.data;return e&&calcDateNum(t)>e?(wx.lin.showToast({title:a||`选择天数不能超过 ${e} 天`}),!1):!(i&&calcDateNum(t)1===compareDay(t,e)&&-1===compareDay(t,i)):-1===compareDay(a,e)?[e]:1===compareDay(a,i)?[i]:[e]:[];if(t===config.TYPE_RANGE){if(r){let[t=e,r]=a;return-1!==compareDay(t,e)&&-1===compareDay(t,i)||(t=e),r||(r=getDayByOffset(getDate(t),1).getTime()),1!==compareDay(r,i)&&-1!==compareDay(r,e)||(r=getDayByOffset(getDate(t),1).getTime()),[t,r]}return[e,getDayByOffset(getDate(e),1).getTime()]}},initRect(){null!==!this.contentObserver&&void 0!==this.contentObserver&&this.contentObserver.disconnect();const t=this.createIntersectionObserver({thresholds:[0,.1,.9,1],observeAll:!0});this.contentObserver=t,t.relativeTo(".calendar-body-wrap"),t.observe(".month",t=>{t.boundingClientRect.top<=t.relativeRect.top&&this.setData({subTitle:formatMonthTitle(t.dataset.date)})})},scrollIntoView(){setTimeout(()=>{const{currentDate:t,type:e,show:a,minDate:i,maxDate:r}=this.data,s="single"===e?t:t[0];if(!s||!a)return;getMonths(i,r).some((t,e)=>0===compareMonth(t,s)&&(this.setData({scrollIntoViewIndex:"month"+e}),!0))},100)},closePicker(){this.setData({show:!1})},onClickConfirm(){const{format:t,type:e,currentDate:a}=this.data;eventBus.emit("lin-form-blur-"+this.id,this.id);let i=null;i="single"===e?"timestamp"!==t?formatFlags.format("yyyy-MM-dd",a):a:a.map(e=>"timestamp"!==t?formatFlags.format("yyyy-MM-dd",e):e),this.triggerEvent("linconfirm",i)},getValues(){return this.data.currentDate},reset(){this.setData({currentDate:null})}}}); \ No newline at end of file diff --git a/dist/checkbox-group/index.js b/dist/checkbox-group/index.js index 65474516..1ee39531 100644 --- a/dist/checkbox-group/index.js +++ b/dist/checkbox-group/index.js @@ -1 +1 @@ -import eventBus from"../core/utils/event-bus";import rules from"../behaviors/rules";Component({behaviors:["wx://form-field",rules],externalClasses:["l-class","l-error-text","l-error-text-class"],relations:{"../checkbox/index":{type:"child",linked(e){this.init(e)},linkChanged(){},unlinked(){}}},properties:{placement:{type:String,value:"column"},maxSelected:{type:[Number,null],value:null},minSelected:{type:[Number,null],value:null}},data:{},attached(){let{minSelected:e,maxSelected:t}=this.properties;this.checkMax(e,t)},methods:{init(e){void 0===this._keys&&(this._keys={}),void 0===this._selected&&(this._selected={}),this.checkDefaultItem(e),this.checkedKeyRepeat(e)},checkedKeyRepeat(e){let{key:t}=e.properties;if(this._keys[t])throw new Error("keys有重复元素, checkbox的key属性不能重复:"+t);this._keys[t]=!0},checkDefaultItem(e){const{key:t,checked:l,cell:s}=e.properties;l&&(this._selected[t]={...s,checked:!0,value:t})},checkMax(e,t){if(null!==e&&e<0)throw new Error("最小选择个数必须大于等于0");if(null!==t&&t<0)throw new Error("最多选择个数必须大于0");if(null!==t&&null!==e&&e>=t)throw new Error("最多选择个数必须大于最小选择个数")},onEmitEventHandle(e){e.checked?this.addSelect(e):this.removeSelect(e.key),this.validatorData({[this.data.name]:Object.values(this._selected)}),this.triggerEvent("linchange",e,{bubbles:!0,composed:!0}),eventBus.emit("lin-form-change-"+this.id,this.id)},onEmitOverflowHandle(e){this.triggerEvent("linout",e,{bubbles:!0,composed:!0})},removeSelect(e){delete this._selected[e]},addSelect(e){let{key:t,...l}=e;this._selected[t]={...l,value:t}},getValues(){return Object.values(this._selected)},reset(){this._selected={};return this.getRelationNodes("../checkbox/index").forEach(e=>e.setData({checked:!1}))}}}); \ No newline at end of file +import eventBus from"../core/utils/event-bus";import rules from"../behaviors/rules";Component({behaviors:["wx://form-field",rules],externalClasses:["l-class","l-error-text","l-error-text-class"],relations:{"../checkbox/index":{type:"child",linked(e){this.init(e)},linkChanged(){},unlinked(){}}},properties:{placement:{type:String,value:"column"},maxSelected:{type:Number,value:null},minSelected:{type:Number,value:null}},data:{},attached(){let{minSelected:e,maxSelected:t}=this.properties;this.checkMax(e,t)},methods:{init(e){void 0===this._keys&&(this._keys={}),void 0===this._selected&&(this._selected={}),this.checkDefaultItem(e),this.checkedKeyRepeat(e)},checkedKeyRepeat(e){let{key:t}=e.properties;if(this._keys[t])throw new Error("keys有重复元素, checkbox的key属性不能重复:"+t);this._keys[t]=!0},checkDefaultItem(e){const{key:t,checked:l,cell:s}=e.properties;l&&(this._selected[t]={...s,checked:!0,value:t})},checkMax(e,t){if(null!==e&&e<0)throw new Error("最小选择个数必须大于等于0");if(null!==t&&t<0)throw new Error("最多选择个数必须大于0");if(null!==t&&null!==e&&e>=t)throw new Error("最多选择个数必须大于最小选择个数")},onEmitEventHandle(e){e.checked?this.addSelect(e):this.removeSelect(e.key),this.validatorData({[this.data.name]:Object.values(this._selected)}),this.triggerEvent("linchange",e,{bubbles:!0,composed:!0}),eventBus.emit("lin-form-change-"+this.id,this.id)},onEmitOverflowHandle(e){this.triggerEvent("linout",e,{bubbles:!0,composed:!0})},removeSelect(e){delete this._selected[e]},addSelect(e){let{key:t,...l}=e;this._selected[t]={...l,value:t}},getValues(){return Object.values(this._selected)},reset(){this._selected={};return this.getRelationNodes("../checkbox/index").forEach(e=>e.setData({checked:!1}))}}}); \ No newline at end of file diff --git a/dist/image-picker/index.js b/dist/image-picker/index.js index 87447f2a..7190bed1 100644 --- a/dist/image-picker/index.js +++ b/dist/image-picker/index.js @@ -1 +1 @@ -import nodeUtil from"../core/utils/node-util";import deviceUtil from"../utils/device-util";import eventUtil from"../core/utils/event-util";import{promisic}from"../utils/util";Component({options:{pureDataPattern:/urls|cells|preview|remove|sizeType|maxImageSize|clear/},behaviors:["wx://form-field"],externalClasses:["l-class","l-item-class"],properties:{urls:{type:Array,value:null},cells:{type:Array,value:null},size:{type:Number,value:null},mode:{type:String,value:"aspectFit"},preview:{type:Boolean,value:!0},remove:{type:Boolean,value:!0},count:{type:Number,value:9},sizeType:{type:Array|String,value:["original","compressed"]},maxImageSize:{type:Number,value:0},clear:{type:Boolean,value:!1},custom:{type:Boolean,value:!1},value:{type:Array,value:[]}},data:{itemSizePercentage:null},observers:{clear(e){e&&(console.warn("clear 属性已废弃,请使用 linClearImage 函数 或 urls 属性清空图片\n 详情信息参考:"),this.setData({value:[],clear:!1}))},"urls,cells":function(e,t){if(!e&&!t)return;let a=[];if(e)a=e;else if(t)for(const e of t)Object.prototype.hasOwnProperty.call(e,"url")&&a.push(e.url);this.setData({value:a.slice(0,this.data.count)})},async size(e){if(!e)return void this.setData({itemSizePercentage:null});const t=await nodeUtil.getNodeRectFromComponent(this,".lin-image-picker__container"),a=10/e*10-20/deviceUtil.px2rpx(t.right-t.left)*100+"%;";this.setData({itemSizePercentage:a})},custom(e){e&&console.warn("custom 已弃用,请勿使用该属性,直接传入 slot 即可")}},methods:{onTapImage(e){const t=this,a=this.data.value,i=e.currentTarget.dataset.imageIndex,l=a[i],r={all:a,index:i,current:l};eventUtil.emit(this,"lintap",r),this.data.preview&&wx.previewImage({urls:a,current:l,success(){eventUtil.emit(t,"linpreview",r)}},!0)},onTapRemove(e){const t=this.data.value,a=e.currentTarget.dataset.imageIndex,i={all:t,index:a,current:t[a]};eventUtil.emit(this,"linremovetap",i),this.data.remove&&this._removeImageByIndex(a)},async onTapAdd(){let{value:e,count:t,sizeType:a,maxImageSize:i}=this.data;const l=t-e.length;if(e.length>=t||l<=0)return;const r=await promisic(wx.chooseImage)({count:l,sizeType:a,sourceType:["album","camera"]}),s=[],n=[];r.tempFiles.forEach(e=>{const{path:t,size:a}=e;a>i&&i>0?n.push(t):s.push(t)}),this.setData({value:e.concat(s)},()=>{const e={all:this.data.value,current:s,oversize:n};eventUtil.emit(this,"linadd",e),eventUtil.emit(this,"linchange",e),eventUtil.emit(this,"linoversize",e)})},getValues(){return this.data.value},_removeImageByIndex(e){const t=this.data.value,a=t[e];t.splice(e,1);const i={index:e,current:a,all:t};this.setData({value:t},()=>{eventUtil.emit(this,"linremove",i)})},linRemoveImage(e){this._removeImageByIndex(e)},linClearImage(){this.setData({value:[]})},linGetValue(){return this.data.value}}}); \ No newline at end of file +import nodeUtil from"../core/utils/node-util";import deviceUtil from"../utils/device-util";import eventUtil from"../core/utils/event-util";import{promisic}from"../utils/util";Component({options:{pureDataPattern:/urls|cells|preview|remove|sizeType|maxImageSize|clear/},behaviors:["wx://form-field"],externalClasses:["l-class","l-item-class"],properties:{urls:{type:Array,value:null},cells:{type:Array,value:null},size:{type:Number,value:null},mode:{type:String,value:"aspectFit"},preview:{type:Boolean,value:!0},remove:{type:Boolean,value:!0},count:{type:Number,value:9},sizeType:{optionalTypes:[Array,String],value:["original","compressed"]},maxImageSize:{type:Number,value:0},clear:{type:Boolean,value:!1},custom:{type:Boolean,value:!1},value:{type:Array,value:[]}},data:{itemSizePercentage:null},observers:{clear(e){e&&(console.warn("clear 属性已废弃,请使用 linClearImage 函数 或 urls 属性清空图片\n 详情信息参考:"),this.setData({value:[],clear:!1}))},"urls,cells":function(e,t){if(!e&&!t)return;let a=[];if(e)a=e;else if(t)for(const e of t)Object.prototype.hasOwnProperty.call(e,"url")&&a.push(e.url);this.setData({value:a.slice(0,this.data.count)})},async size(e){if(!e)return void this.setData({itemSizePercentage:null});const t=await nodeUtil.getNodeRectFromComponent(this,".lin-image-picker__container"),a=10/e*10-20/deviceUtil.px2rpx(t.right-t.left)*100+"%;";this.setData({itemSizePercentage:a})},custom(e){e&&console.warn("custom 已弃用,请勿使用该属性,直接传入 slot 即可")}},methods:{onTapImage(e){const t=this,a=this.data.value,i=e.currentTarget.dataset.imageIndex,l=a[i],r={all:a,index:i,current:l};eventUtil.emit(this,"lintap",r),this.data.preview&&wx.previewImage({urls:a,current:l,success(){eventUtil.emit(t,"linpreview",r)}},!0)},onTapRemove(e){const t=this.data.value,a=e.currentTarget.dataset.imageIndex,i={all:t,index:a,current:t[a]};eventUtil.emit(this,"linremovetap",i),this.data.remove&&this._removeImageByIndex(a)},async onTapAdd(){let{value:e,count:t,sizeType:a,maxImageSize:i}=this.data;const l=t-e.length;if(e.length>=t||l<=0)return;const r=await promisic(wx.chooseImage)({count:l,sizeType:a,sourceType:["album","camera"]}),s=[],n=[];r.tempFiles.forEach(e=>{const{path:t,size:a}=e;a>i&&i>0?n.push(t):s.push(t)}),this.setData({value:e.concat(s)},()=>{const e={all:this.data.value,current:s,oversize:n};eventUtil.emit(this,"linadd",e),eventUtil.emit(this,"linchange",e),eventUtil.emit(this,"linoversize",e)})},getValues(){return this.data.value},_removeImageByIndex(e){const t=this.data.value,a=t[e];t.splice(e,1);const i={index:e,current:a,all:t};this.setData({value:t},()=>{eventUtil.emit(this,"linremove",i)})},linRemoveImage(e){this._removeImageByIndex(e)},linClearImage(){this.setData({value:[]})},linGetValue(){return this.data.value}}}); \ No newline at end of file diff --git a/dist/input/index.wxml b/dist/input/index.wxml index 3b34a826..db5ce1c8 100644 --- a/dist/input/index.wxml +++ b/dist/input/index.wxml @@ -1,7 +1,7 @@