diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..6a7ff0ca --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +build/*.js +config/*.js +example/*.js +dist \ No newline at end of file diff --git a/build/build.js b/build/build.js deleted file mode 100644 index 580eb5d6..00000000 --- a/build/build.js +++ /dev/null @@ -1,43 +0,0 @@ -const { - src, - dest, - parallel -} = require('gulp'); -const less = require('gulp-less'); -const cssmin = require('gulp-clean-css'); -const rename = require('gulp-rename'); -const del = require('del'); - -const buildWxss = (srcPath, remainPath, distPath) => () => - src([srcPath, remainPath]) - .pipe(less()) - .pipe(cssmin()) - .pipe(rename(srcPath => { - srcPath.extname = '.wxss'; - })) - .pipe(dest(distPath)); - -const copy = (srcPath, distPath, ext) => () => - src(`${srcPath}/*.${ext}`) - .pipe(dest(distPath)); - -const copyStatic = (srcPath, distPath) => - parallel( - copy(srcPath, distPath, 'wxml'), - copy(srcPath, distPath, 'wxs'), - copy(srcPath, distPath, 'json'), - copy(srcPath, distPath, 'js'), - copy(srcPath, distPath, 'png') - ); - -const clean = (cleanPath) => () => - del([cleanPath], { - force: true - }); - -module.exports = { - buildWxss, - copyStatic, - clean, - copy -}; \ No newline at end of file diff --git a/build/index.js b/build/index.js index b7c60154..023a29ea 100644 --- a/build/index.js +++ b/build/index.js @@ -1,9 +1,13 @@ const { buildWxss, + buildWxml, + buildImage, + buildJson, + buildJs, copyStatic, clean, copy -} = require('./build'); +} = require('./task'); const { series, parallel, @@ -30,6 +34,23 @@ module.exports = { `!${srcProPath}/_*.less`, distPath ), + buildWxml( + `${srcProPath}/*.wxml`, + `!${srcProPath}/_*.wxml`, + distPath + ), + buildImage( + `${srcProPath}/*.png`, + distPath + ), + buildJson( + `${srcProPath}/*.json`, + distPath + ), + buildJs( + `${srcProPath}/*.js`, + distPath + ), copyStatic( srcProPath, distPath @@ -46,7 +67,8 @@ module.exports = { ), copyStatic( srcDevPath, - examplePath + examplePath, + 'dev' ) ) ), diff --git a/build/task.js b/build/task.js new file mode 100644 index 00000000..37b88ef5 --- /dev/null +++ b/build/task.js @@ -0,0 +1,83 @@ +const { + src, + dest, + parallel +} = require('gulp'); +const less = require('gulp-less'); +const imagemin = require('gulp-imagemin'); +const cssmin = require('gulp-clean-css'); +const jsonmin = require('gulp-jsonminify'); +const jsmin = require('gulp-uglify-es').default; +const wxmlmin = require('gulp-htmlmin'); +const rename = require('gulp-rename'); +const del = require('del'); + +const buildWxss = (srcPath, remainPath, distPath) => () => + src([srcPath, remainPath]) + .pipe(less()) + .pipe(cssmin()) + .pipe(rename(srcPath => { + srcPath.extname = '.wxss'; + })) + .pipe(dest(distPath)); + +const copy = (srcPath, distPath, ext) => () => + src(`${srcPath}/*.${ext}`) + .pipe(dest(distPath)); + +const buildWxml = (srcPath, remainPath, distPath) => () => + src([srcPath, remainPath]) + .pipe(wxmlmin({ + removeComments: true, + // collapseWhitespace: true, + keepClosingSlash: true, + caseSensitive: true + })) + .pipe(dest(distPath)); + +const buildJson = (srcPath, distPath) => () => + src(srcPath) + .pipe(jsonmin()) + .pipe(dest(distPath)); + +const buildJs = (srcPath, distPath) => () => + src(srcPath) + .pipe(jsmin()) + .pipe(dest(distPath)); + +const buildImage = (srcPath, distPath) => () => + src(srcPath) + .pipe(imagemin()) + .pipe(dest(distPath)); + +const copyStatic = (srcPath, distPath, env = 'build') => { + if (env === 'build') { + return parallel( + copy(srcPath, distPath, 'wxs') + ); + } else { + return parallel( + copy(srcPath, distPath, 'wxml'), + copy(srcPath, distPath, 'wxs'), + copy(srcPath, distPath, 'json'), + copy(srcPath, distPath, 'js'), + copy(srcPath, distPath, 'png') + ); + } +} + +const clean = (cleanPath) => () => + del([cleanPath], { + force: true + }); + +module.exports = { + buildWxss, + buildWxml, + buildImage, + buildJson, + buildJs, + copyStatic, + clean, + copy +}; \ No newline at end of file diff --git a/dist/action-sheet/index.js b/dist/action-sheet/index.js index 76919095..5d5e83d4 100644 --- a/dist/action-sheet/index.js +++ b/dist/action-sheet/index.js @@ -1,124 +1 @@ -import zIndex from '../behaviors/zIndex'; -import hover from '../behaviors/hover'; - -Component({ - behaviors: [zIndex,hover], - externalClasses: ['l-class-title', 'l-class-item', 'l-class-cancel','l-title-class','l-item-class','l-cancel-class'], - properties: { - locked: Boolean, - showCancel: Boolean, - show: Boolean, - itemList: Array, - cancelText: { - type: String, - value: '取消' - }, - title: String, - zIndex:{ - type:Number, - value: 777 - }, - openApi: { - type: Boolean, - value: true, - } - }, - data: { - success: '', - fail: '', - isIphoneX: false - }, - attached() { - if (this.data.openApi) { - this.initActionSheet(); - } - this.initUIAdapter(); - }, - - pageLifetimes: { - show() { - if (this.data.openApi) { - this.initActionSheet(); - } - - }, - }, - methods: { - /** - * 区分UI尺寸 - */ - initUIAdapter() { - wx.getSystemInfo({ - success: (res) => { - this.setData({ - isIphoneX: res.model == 'iPhone X' ? true : false, - }); - } - }); - }, - initActionSheet() { - wx.lin = wx.lin || {}; - wx.lin.showActionSheet = (options={}) => { - const { - itemList = [], - success = null, - fail = null, - title = '', - locked = false, - cancelText = '取消', - showCancel = false, - } = options; - this.setData({ - itemList: itemList.slice(0, 10), - success, - fail, - title, - locked, - cancelText, - showCancel, - show: true, - }); - return this; - }; - }, - handleClickItem(e) { - const { - success - } = this.data; - success && success({ ...e.currentTarget.dataset }); - this.triggerEvent('linitemtap', { ...e.currentTarget.dataset },{ bubbles: true, composed: true }); - this._hideActionSheet(); - }, - - _showActionSheet() { - this.setData({ - show: true - }); - }, - - _hideActionSheet() { - this.setData({ - show: false - }); - }, - - handleClickCancel() { - const { - fail - } = this.data; - fail && fail({ - errMsg: 'showactionsheet:fail cancel' - }); - this.triggerEvent('lincancel', { - errMsg: 'showactionsheet:fail cancel' - },{ bubbles: true, composed: true }); - this._hideActionSheet(); - }, - - handleClickPopUp() { - if (!this.data.locked) { - this.handleClickCancel(); - } - }, - } -}); \ No newline at end of file +import zIndex from"../behaviors/zIndex";import hover from"../behaviors/hover";Component({behaviors:[zIndex,hover],externalClasses:["l-class-title","l-class-item","l-class-cancel","l-title-class","l-item-class","l-cancel-class"],properties:{locked:Boolean,showCancel:Boolean,show:Boolean,itemList:Array,cancelText:{type:String,value:"取消"},title:String,zIndex:{type:Number,value:777},openApi:{type:Boolean,value:!0}},data:{success:"",fail:"",isIphoneX:!1},attached(){this.data.openApi&&this.initActionSheet(),this.initUIAdapter()},pageLifetimes:{show(){this.data.openApi&&this.initActionSheet()}},methods:{initUIAdapter(){wx.getSystemInfo({success:e=>{this.setData({isIphoneX:"iPhone X"==e.model})}})},initActionSheet(){wx.lin=wx.lin||{},wx.lin.showActionSheet=(e={})=>{const{itemList:t=[],success:s=null,fail:i=null,title:a="",locked:l=!1,cancelText:n="取消",showCancel:c=!1}=e;return this.setData({itemList:t.slice(0,10),success:s,fail:i,title:a,locked:l,cancelText:n,showCancel:c,show:!0}),this}},handleClickItem(e){const{success:t}=this.data;t&&t({...e.currentTarget.dataset}),this.triggerEvent("linitemtap",{...e.currentTarget.dataset},{bubbles:!0,composed:!0}),this._hideActionSheet()},_showActionSheet(){this.setData({show:!0})},_hideActionSheet(){this.setData({show:!1})},handleClickCancel(){const{fail:e}=this.data;e&&e({errMsg:"showactionsheet:fail cancel"}),this.triggerEvent("lincancel",{errMsg:"showactionsheet:fail cancel"},{bubbles:!0,composed:!0}),this._hideActionSheet()},handleClickPopUp(){this.data.locked||this.handleClickCancel()}}}); \ No newline at end of file diff --git a/dist/action-sheet/index.json b/dist/action-sheet/index.json index 248ca904..f301e159 100644 --- a/dist/action-sheet/index.json +++ b/dist/action-sheet/index.json @@ -1,8 +1 @@ -{ - "component": true, - "usingComponents": { - "l-icon":"../icon/index", - "l-popup":"../popup/index", - "l-button":"../button/index" - } - } \ No newline at end of file +{"component":true,"usingComponents":{"l-icon":"../icon/index","l-popup":"../popup/index","l-button":"../button/index"} } \ No newline at end of file diff --git a/dist/action-sheet/index.wxml b/dist/action-sheet/index.wxml index 64e0d9c4..8b114a3b 100644 --- a/dist/action-sheet/index.wxml +++ b/dist/action-sheet/index.wxml @@ -1,18 +1,13 @@ - - + + {{ title }} - + {{ item.name }} diff --git a/dist/action-sheet/index.wxss b/dist/action-sheet/index.wxss index fc975429..f85a7d89 100644 --- a/dist/action-sheet/index.wxss +++ b/dist/action-sheet/index.wxss @@ -1 +1 @@ -.l-action-sheet{background:#f7f7f7}.l-item-button{height:88rpx;line-height:88rpx;text-align:center;background:#fff;border-bottom:2rpx solid #f3f3f3;font-size:28rpx;color:#45526b;display:flex;align-items:center;justify-content:center;width:100%}.l-cancel{margin-top:12rpx}.l-cancel-x .l-item-button{padding-bottom:44rpx}.l-image-button>text{margin-left:20rpx}.list-hover{opacity:.8} \ No newline at end of file +.l-action-sheet{background:#f7f7f7}.l-item-button{height:88rpx;line-height:88rpx;text-align:center;background:#fff;border-bottom:2rpx solid #f3f3f3;font-size:28rpx;color:#45526b;display:flex;align-items:center;justify-content:center;width:100%;overflow:hidden}.l-cancel{margin-top:12rpx}.l-cancel-x .l-item-button{padding-bottom:44rpx}.l-image-button>text{margin-left:20rpx}.list-hover{opacity:.8} \ No newline at end of file diff --git a/dist/album/index.js b/dist/album/index.js index 2ad43240..35ab9c46 100644 --- a/dist/album/index.js +++ b/dist/album/index.js @@ -1,166 +1 @@ -// miniprogram_npm/lin-ui/album/index.js -Component({ - /** - * 组件的属性列表 - */ - externalClasses: ['l-class', 'l-single-image-class', 'l-multi-image-class'], - properties: { - urls: { - type: Array - }, - // 是否可以预览 - preview: { - type: Boolean, - value: true - }, - gapRow: { - type: Number, - value: 10, - }, - gapColumn: { - type: Number, - value: 10, - }, - // 单图时长边大小 - singleSize: { - type: Number, - value: 360, - }, - // 多图时图片边长 - multipleSize: { - type: Number, - value: 158, - }, - // 单图显示模式 - singleMode: { - type: String, - value: 'aspectFit', - }, - // 多图显示模式 - multipleMode: { - type: String, - value: 'aspectFill', - }, - key: { - type: String, - value: 'url' - } - }, - - /** - * 组件的初始数据 - */ - data: { - // 传值方式是新方式还是旧方式 - newType: true, - // 单图短边大小 - shortSideValue: 0, - // 图片排列几行 - row: 0, - // 图片排列几列 - colum: 0, - }, - - /** - * 组件的生命周期 - */ - lifetimes: { - attached() { - // 在组件实例进入页面节点树时执行 - - //判断传入urls长度 - if (this.data.urls.length > 9) { - const urls = this.data.urls.slice(0, 9); - this.setData({ - urls - }); - console.warn('超过9张图片!'); - } - - this.preview(); - - }, - }, - - /** - * 组件的方法列表 - */ - methods: { - // 判断传入的urls是字符串列表(old模式)还是对象列表(new模式) - judgeType() { - const urls = this.data.urls; - if (urls.length != 0) { - if (typeof (urls[0]) !== 'object') { - return false; - } - } - return true; - }, - - //判断照片是横屏还是竖屏并计算短边的长度 - //如不指定短边的长度,短边会默认显示image组件的长度 - horizontalOrVertical: function (src) { - wx.getImageInfo({ - src: src, - success: (res) => { - const longSide = res.width >= res.height ? res.width : res.height; - const shortSide = res.width >= res.height ? res.height : res.width; - this.setData({ - horizontalScreen: res.width >= res.height ? true : false, - shortSideValue: shortSide * this.data.singleSize / longSide - }); - } - }); - }, - - // 显示图片 - preview: function () { - // 判断传入模式 - const newType = this.judgeType(); - this.setData({ - newType - }); - //显示图片 - const urls = this.data.urls; - const key = this.data.key; - - if (urls.length == 1) { - this.horizontalOrVertical(newType ? urls[0][key] : urls[0]); - } - }, - - onPreviewTap(e) { - const index = e.currentTarget.id; - const urls = this.data.urls; - let tempFilePath = ''; - let previewImageList = []; - const newType = this.data.newType; - const key = this.data.key; - - if (newType) { - tempFilePath = urls[index][key]; - for (let i = 0; i < urls.length; i++) { - previewImageList.push(urls[i][key]); - } - } else { - tempFilePath = urls[index]; - previewImageList = urls; - } - - let detail = { - index, // 下标 - current: urls[index], // 当前显示图片的http链接 - all: urls // 需要预览的图片http链接列表 - }; - let option = {}; - if (this.data.preview === true) { - wx.previewImage({ - current: tempFilePath, // 当前显示图片的http链接 - urls: previewImageList // 需要预览的图片http链接列表 - }); - } - this.triggerEvent('lintap', detail, option); - } - - } -}); \ No newline at end of file +Component({externalClasses:["l-class","l-single-image-class","l-multi-image-class"],properties:{urls:{type:Array},preview:{type:Boolean,value:!0},gapRow:{type:Number,value:10},gapColumn:{type:Number,value:10},singleSize:{type:Number,value:360},multipleSize:{type:Number,value:158},singleMode:{type:String,value:"aspectFit"},multipleMode:{type:String,value:"aspectFill"},key:{type:String,value:"url"}},data:{newType:!0,shortSideValue:0,row:0,colum:0},lifetimes:{attached(){if(this.data.urls.length>9){const e=this.data.urls.slice(0,9);this.setData({urls:e}),console.warn("超过9张图片!")}this.preview()}},methods:{judgeType(){const e=this.data.urls;return 0==e.length||"object"==typeof e[0]},horizontalOrVertical:function(e){wx.getImageInfo({src:e,success:e=>{const t=e.width>=e.height?e.width:e.height,i=e.width>=e.height?e.height:e.width;this.setData({horizontalScreen:e.width>=e.height,shortSideValue:i*this.data.singleSize/t})}})},preview:function(){const e=this.judgeType();this.setData({newType:e});const t=this.data.urls,i=this.data.key;1==t.length&&this.horizontalOrVertical(e?t[0][i]:t[0])},onPreviewTap(e){const t=e.currentTarget.id,i=this.data.urls;let a="",s=[];const l=this.data.newType,r=this.data.key;if(l){a=i[t][r];for(let e=0;e - + \ No newline at end of file diff --git a/dist/avatar/index.js b/dist/avatar/index.js index cec5f2a7..afe8b943 100644 --- a/dist/avatar/index.js +++ b/dist/avatar/index.js @@ -1,70 +1 @@ -Component({ - externalClasses: [ - 'l-class', - 'l-class-text', - 'l-text-class' - ], - properties: { - icon: String, - iconColor: { - type: String, - value: '#3963BC' - }, - iconSize: { - type: String, - value: '28' - }, - text: String, - src: String, - openData: { - type: Array, - observer: '_initOpenData' - }, - shape: { - type: String, - value: 'circle' - }, - mode: { - type: String, - value: 'scaleToFill' - }, - size: { - type: Number, - value: 120, - }, - placement: { - type: String, - value: 'right' - }, - }, - data: { - _isHaveUserNickName: false, - _isHaveUserAvatarUrl: false, - _iconSize: '', - _iconColor: '#ffffff' - }, - methods: { - _initOpenData: function (openData) { - this._isHaveUserAvatarUrl(openData); - this._isHaveUserNickName(openData); - }, - - _isHaveUserAvatarUrl: function (openData) { - this.setData({ - _isHaveUserAvatarUrl: openData.indexOf('userAvatarUrl') !== -1 - }); - }, - - _isHaveUserNickName: function (openData) { - this.setData({ - _isHaveUserNickName: openData.indexOf('userNickName') !== -1 - }); - }, - tapAvatar: function (e) { - this.triggerEvent('lintap', e, { - bubbles: true, - composed: true - }); - }, - } -}); \ No newline at end of file +Component({externalClasses:["l-class","l-class-text","l-text-class"],properties:{icon:String,iconColor:{type:String,value:"#3963BC"},iconSize:{type:String,value:"28"},text:String,src:String,openData:{type:Array,observer:"_initOpenData"},shape:{type:String,value:"circle"},mode:{type:String,value:"scaleToFill"},size:{type:Number,value:120},placement:{type:String,value:"right"}},data:{_isHaveUserNickName:!1,_isHaveUserAvatarUrl:!1,_iconSize:"",_iconColor:"#ffffff"},methods:{_initOpenData:function(e){this._isHaveUserAvatarUrl(e),this._isHaveUserNickName(e)},_isHaveUserAvatarUrl:function(e){this.setData({_isHaveUserAvatarUrl:-1!==e.indexOf("userAvatarUrl")})},_isHaveUserNickName:function(e){this.setData({_isHaveUserNickName:-1!==e.indexOf("userNickName")})},tapAvatar:function(e){this.triggerEvent("lintap",e,{bubbles:!0,composed:!0})}}}); \ No newline at end of file diff --git a/dist/avatar/index.json b/dist/avatar/index.json index dd10af0a..a1fa4d66 100644 --- a/dist/avatar/index.json +++ b/dist/avatar/index.json @@ -1,6 +1 @@ -{ - "component": true, - "usingComponents": { - "l-icon":"../icon/index" - } - } \ No newline at end of file +{"component":true,"usingComponents":{"l-icon":"../icon/index"} } \ No newline at end of file diff --git a/dist/avatar/index.wxml b/dist/avatar/index.wxml index 6703bd16..25e9b7cd 100644 --- a/dist/avatar/index.wxml +++ b/dist/avatar/index.wxml @@ -1,12 +1,12 @@ - - - + + + - + {{text}} \ No newline at end of file diff --git a/dist/badge/index.js b/dist/badge/index.js index 27775b7c..e85fc3f6 100644 --- a/dist/badge/index.js +++ b/dist/badge/index.js @@ -1,87 +1 @@ -Component({ - externalClasses: ['l-class', 'l-class-self', 'l-self-class'], - properties: { - // 红点模式 - dot: { - type: Boolean, - value: false - }, - shape: { - type: String, - value: 'horn' - }, - value: { - type: String, - value: '0' - }, - mode: { - type: String, - value: 'number' - }, - // 数字最大值 - maxCount: { - type: Number, - value: 99 - }, - // 数字形式 - numberType: { - type: String, - value: 'overflow' - }, - show: { - type: Boolean, - value: true - } - }, - data: { - finalCount: 0 - }, - observers: { - 'value': function () { - this.finalCount(); - } - }, - methods: { - // 最终数字 - finalCount() { - if (isNaN(Number(this.data.value)) || (this.data.mode === 'text')) { - this.setData({ - finalCount: this.data.value - }); - } else { - this.switchType(); - } - }, - switchType() { - switch (this.data.numberType) { - case 'overflow': - this.setData({ - finalCount: Number(this.data.value) > Number(this.data.maxCount) ? `${this.data.maxCount}+` : this.data.value - }); - break; - case 'ellipsis': - this.setData({ - finalCount: Number(this.data.value) > Number(this.data.maxCount) ? `...` : this.data.value - }); - break; - case 'limit': - this.setData({ - finalCount: Number(this.data.value) > 999 ? (Number(this.data.value) >= 9999 ? Math.floor(this.data.value / 10000 * 100) / 100 + `w` : Math.floor(this.data.value / 1000 * 100) / 100 + `k`) : this.data.value - }); - break; - default: - this.setData({ - finalCount: Number(this.data.value) - }); - break; - } - }, - // 点击事件 - handleTap() { - this.triggerEvent('lintap', {}, { - bubbles: true, - composed: true - }); - }, - } -}); \ No newline at end of file +Component({externalClasses:["l-class","l-class-self","l-self-class"],properties:{dot:{type:Boolean,value:!1},shape:{type:String,value:"horn"},value:{type:String,value:"0"},mode:{type:String,value:"number"},maxCount:{type:Number,value:99},numberType:{type:String,value:"overflow"},show:{type:Boolean,value:!0}},data:{finalCount:0},observers:{value:function(){this.finalCount()}},methods:{finalCount(){isNaN(Number(this.data.value))||"text"===this.data.mode?this.setData({finalCount:this.data.value}):this.switchType()},switchType(){switch(this.data.numberType){case"overflow":this.setData({finalCount:Number(this.data.value)>Number(this.data.maxCount)?`${this.data.maxCount}+`:this.data.value});break;case"ellipsis":this.setData({finalCount:Number(this.data.value)>Number(this.data.maxCount)?"...":this.data.value});break;case"limit":this.setData({finalCount:Number(this.data.value)>999?Number(this.data.value)>=9999?Math.floor(this.data.value/1e4*100)/100+"w":Math.floor(this.data.value/1e3*100)/100+"k":this.data.value});break;default:this.setData({finalCount:Number(this.data.value)})}},handleTap(){this.triggerEvent("lintap",{},{bubbles:!0,composed:!0})}}}); \ No newline at end of file diff --git a/dist/badge/index.json b/dist/badge/index.json index e56592f8..1450e2ec 100644 --- a/dist/badge/index.json +++ b/dist/badge/index.json @@ -1,6 +1 @@ -{ - "component": true, - "usingComponents": { - - } -} \ No newline at end of file +{"component":true,"usingComponents":{}} \ No newline at end of file diff --git a/dist/badge/index.wxml b/dist/badge/index.wxml index 2854d246..4d7df27e 100644 --- a/dist/badge/index.wxml +++ b/dist/badge/index.wxml @@ -1,7 +1,7 @@ - + {{finalCount}} \ No newline at end of file diff --git a/dist/behaviors/computeOffset.js b/dist/behaviors/computeOffset.js index 381f723a..0811be9e 100644 --- a/dist/behaviors/computeOffset.js +++ b/dist/behaviors/computeOffset.js @@ -1,19 +1 @@ -// eslint-disable-next-line no-undef -export default Behavior({ - behaviors: [], - properties: {}, - data: { - distance: 0 - }, - attached(){ - this.offsetMargin(); - }, - methods: { - offsetMargin() { - const { windowHeight, screenHeight } = wx.getSystemInfoSync(); - this.setData({ - distance: (screenHeight-windowHeight ) - }); - } - } -}); \ No newline at end of file +export default Behavior({behaviors:[],properties:{},data:{distance:0},attached(){this.offsetMargin()},methods:{offsetMargin(){const{windowHeight:t,screenHeight:e}=wx.getSystemInfoSync();this.setData({distance:e-t})}}}); \ No newline at end of file diff --git a/dist/behaviors/countdown.js b/dist/behaviors/countdown.js index 5056f596..b5efbeb9 100644 --- a/dist/behaviors/countdown.js +++ b/dist/behaviors/countdown.js @@ -1,222 +1 @@ -// eslint-disable-next-line no-undef -export default Behavior({ - behaviors: [], - properties: { - time: { - type: Date, - value: new Date().getTime() + 86400000, - observer: function (newVal, oldVal) { - if (newVal && !oldVal) { - this.getLatestTime(); - } - } - }, - status: { - type: Boolean, - value: true, - observer: function (newVal) { - if (newVal) { - this.init(); - } else if (!newVal) { - clearInterval(this.data.timer); - } - } - }, - timeType: { - type: String, - value: 'datetime' - }, - format: { - type: String, - value: '{%d}天{%h}时{%m}分{%s}秒' - }, - isZeroPadd: { - type: Boolean, - value: true, - }, - countdownType: { - type: String, - value: 'normal' - }, - isClearInterval: { - type: Boolean, - value: true - } - }, - data: { - initAddTime: 0, - timer: null, - date: [], - }, - ready: function () { - this.getLatestTime(); - }, - - detached: function () { - if (this.data.isClearInterval) { - clearInterval(this.data.timer); - } - }, - - pageLifetimes: { - hide() { - if (this.data.isClearInterval) { - clearInterval(this.data.timer); - } - - }, - show() { - if (this.data.isClearInterval) { - this.getLatestTime(); - } - } - }, - - methods: { - // 自动补零 - zeroPadding(num) { - num = num.toString(); - return num[1] ? num : '0' + num; - }, - - init() { - clearInterval(this.data.timer); - const timer = setTimeout(() => { - this.getLatestTime.call(this); - }, 1000); - this.setData({ - timer - }); - }, - - getLatestTime() { - let { - time, - status, - timeType, - initAddTime, - countdownType, - } = this.data; - // IOS不支持2019-04-23 的日期格式 - let countDownTime = time; - if (countdownType === 'normal') { //当countdownType === normal时,不影响之前的代码 - if (timeType !== 'second') { - countDownTime = typeof time === 'string' ? countDownTime.replace(/-/g, '/') : countDownTime; - countDownTime = Math.ceil((new Date(countDownTime).getTime() - new Date().getTime()) / 1000); - } - - if (countDownTime < 0 && timeType !== 'second') { - this._getTimeValue(0); - this.CountdownEnd(); - return; - } - - if (countDownTime - initAddTime > 0) { - this.getLatestForCountDown(countDownTime); - } else if (countDownTime - initAddTime < 0) { - this.getLatestForAddTime(countDownTime); - } else if (countDownTime - initAddTime === 0) { - if (initAddTime <= 0) { - this._getTimeValue(countDownTime); - } - this.CountdownEnd(); - } - - if (status && countDownTime - initAddTime !== 0) { - this.init.call(this); - } - - } else if (countdownType === 'anniversary') { // 当countdownType === anniversary时,为纪念日模式 - if (timeType === 'second') { // 纪念日模式不能设置timeType === second - console.error(`countdownType为${countdownType}类型时,不可设置timeType值为second`); - } else { - countDownTime = typeof time === 'string' ? countDownTime.replace(/-/g, '/') : countDownTime; - countDownTime = Math.ceil((new Date().getTime() - new Date(countDownTime).getTime()) / 1000); - if (countDownTime >= 0) { // countDownTime计算结果不能为负数 - this.getLatestForCountDown(countDownTime); - this.init.call(this); - } else { - console.error('time传值错误'); - } - } - } else { // countdownType 不能设置为 normal,anniversary 以外的值 - console.error('错误的countdownType类型'); - } - }, - - getLatestForAddTime(countDownTime) { - let { - initAddTime - } = this.data; - if (initAddTime !== Math.abs(countDownTime)) { - initAddTime++; - this._getTimeValue(initAddTime); - this.setData({ - initAddTime - }); - } - }, - - getLatestForCountDown(countDownTime) { - this._getTimeValue(countDownTime); - this.setData({ - time: this.data.timeType === 'second' ? --countDownTime : this.data.time, - }); - }, - - _getTimeValue(countDownTime) { - const { - format - } = this.data; - const date = []; - const fomatArray = format.split(/(\{.*?\})/); - const formatType = [{ - key: '{%d}', - type: 'day', - count: 86400 - }, { - key: '{%h}', - type: 'hour', - count: 3600 - }, { - key: '{%m}', - type: 'minute', - count: 60 - }, { - key: '{%s}', - type: 'second', - count: 1, - }]; - let diffSecond = countDownTime; - formatType.forEach(format => { - const index = this._findTimeName(fomatArray, format.key); - if (index === -1) return; - const name = fomatArray[index]; - const formatItem = { - type: format.type, - name, - value: parseInt(diffSecond / format.count) - }; - if (this.data.isZeroPadd) { - formatItem.value = this.zeroPadding(formatItem.value); - } - diffSecond %= format.count; - date.push(formatItem); - }); - this.setData({ - date - }); - return date; - }, - - _findTimeName(fomatArray, str) { - const index = fomatArray.indexOf(str); - if (index === -1) return -1; - return index + 1; - }, - - CountdownEnd() { - this.triggerEvent('linend', {}); - }, - } -}); \ No newline at end of file +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 diff --git a/dist/behaviors/hover.js b/dist/behaviors/hover.js index 1cd5d97c..266b0f51 100644 --- a/dist/behaviors/hover.js +++ b/dist/behaviors/hover.js @@ -1,10 +1 @@ -// eslint-disable-next-line no-undef -export default Behavior({ - behaviors: [], - properties: { - isHover:{ - type: Boolean, - value: true - } - } -}); \ No newline at end of file +export default Behavior({behaviors:[],properties:{isHover:{type:Boolean,value:!0}}}); \ No newline at end of file diff --git a/dist/behaviors/rules.js b/dist/behaviors/rules.js index b951893e..9c951699 100644 --- a/dist/behaviors/rules.js +++ b/dist/behaviors/rules.js @@ -1,133 +1 @@ -import Schema from '../common/async-validator/index'; -/** - * @param tipType String [toast , message , text] - */ -// eslint-disable-next-line no-undef -export default Behavior({ - behaviors: [], - properties: { - // 校验 - rules: { - type: [Object,Array], - value: [] - }, - tipType: { - type: String, - value:'toast' - } - }, - data: { - schema: '', - tipFun: { - 'message': 'showMessage', - 'toast': 'showToast', - }, - tipContent: { - 'message': 'content', - 'toast': 'title', - }, - errorText: '', - errors: [] - }, - - methods: { - initRules() { - // const rulesName = this.data.name; - const { - rules - } = this.data; - if (!rules) return; - // 如果rule 是单个object - if(Object.prototype.toString.call(rules) === '[object Object]') { - this.data.rules = [rules]; - } - - this.data.rules.forEach(item => { - if(!item.trigger) { - item.trigger = []; - return; - } - if(typeof item.trigger === 'string') { - item.trigger = [item.trigger]; - return; - } - // if(Object.prototype.toString.call(item.trigger) === '[object Object]') { - // item.trigger = ['blur']; - // return; - // } - }); - - }, - getNeedValidateRule(type) { - const rulesName = this.data.name; - const { - rules - } = this.data; - if (!rules) return; - - const list = type ? rules.filter(item => { - return item.trigger.indexOf(type) > -1; - }): rules; - const schema = new Schema({ - [rulesName]: list, - }); - this.setData({ - schema, - }); - return list; - }, - validatorData(value, type) { - const { - tipType, - tipFun, - tipContent - } = this.data; - const rules = this.getNeedValidateRule(type); - - if (!rules) return; - - this.data.schema.validate(value, (errors) => { - this.setData({ - errors: errors || [] - }); - - this.triggerEvent('linvalidate', { - errors, - isError: !!errors - }); - - if (errors && tipType) { - const funName = tipFun[tipType]; - const contentName = tipContent[tipType]; - if (tipType === 'text') { - this.setData({ - errorText: errors[0].message - }); - return errors; - } - - if (!wx.lin || !wx.lin[funName]) { - wx.showToast({ - icon: 'none', - title: `请在页面内引入${tipType}组件` - }); - return errors; - } - - wx.lin[funName] && wx.lin[funName]({ - [contentName]: errors[0].message, - duration: 1500, - mask: false, - }); - return errors; - } else if (!errors && tipType) { - this.setData({ - errorText: '' - }); - } - - }); - - } - } -}); +import Schema from"../common/async-validator/index";export default Behavior({behaviors:[],properties:{rules:{type:[Object,Array],value:[]},tipType:{type:String,value:"toast"}},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)&&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/behaviors/scrollCenter.js b/dist/behaviors/scrollCenter.js index 5d54661c..50437c9a 100644 --- a/dist/behaviors/scrollCenter.js +++ b/dist/behaviors/scrollCenter.js @@ -1,54 +1 @@ -// eslint-disable-next-line no-undef -export default Behavior({ - methods: { - getRect(selector, all = false) { - return new Promise((resolve, reject) => { - const query = wx.createSelectorQuery().in(this); - const type = all ? query.selectAll(selector) : query.select(selector); - type.boundingClientRect((res) => { - if (!res) return reject('找不到元素'); - resolve(res); - }).exec(); - }); - }, - queryScrollNode(res, currentIndex, type = 'width') { - const currentRect = res[currentIndex]; - - this.getRect('.l-tabsscroll').then(_ => { - const scrollWidth = _[type]; - - let transformDistance = res - .slice(0, currentIndex) - .reduce((prev, curr) => prev + curr[type], 0); - - transformDistance += (currentRect[type] - scrollWidth) / 2; - - if (type === 'width') { - this.setData({ - transformX: transformDistance, - transformY: 0 - }); - } else { - this.setData({ - transformX: 0, - transformY: transformDistance - }); - } - }); - }, - queryMultipleNodes() { - const { - placement, - currentIndex - } = this.data; - this.getRect('.l-tabs-item', true) - .then((res) => { - if (['top', 'bottom'].indexOf(placement) !== -1) { - this.queryScrollNode(res, currentIndex); - } else { - this.queryScrollNode(res, currentIndex, 'height'); - } - }); - } - } -}); \ No newline at end of file +export default Behavior({methods:{getRect(t,e=!1){return new Promise((r,s)=>{const o=wx.createSelectorQuery().in(this);(e?o.selectAll(t):o.select(t)).boundingClientRect(t=>{if(!t)return s("找不到元素");r(t)}).exec()})},queryScrollNode(t,e,r="width"){const s=t[e];this.getRect(".l-tabsscroll").then(o=>{const l=o[r];let c=t.slice(0,e).reduce((t,e)=>t+e[r],0);c+=(s[r]-l)/2,"width"===r?this.setData({transformX:c,transformY:0}):this.setData({transformX:0,transformY:c})})},queryMultipleNodes(){const{placement:t,currentIndex:e}=this.data;this.getRect(".l-tabs-item",!0).then(r=>{-1!==["top","bottom"].indexOf(t)?this.queryScrollNode(r,e):this.queryScrollNode(r,e,"height")})}}}); \ No newline at end of file diff --git a/dist/behaviors/watchShow.js b/dist/behaviors/watchShow.js index d2569e84..1bf924e5 100644 --- a/dist/behaviors/watchShow.js +++ b/dist/behaviors/watchShow.js @@ -1,26 +1 @@ -// eslint-disable-next-line no-undef -export default Behavior({ - observers: { - 'show': function (show) { - show && this.changeStatus(); - if (!show) this.setData({ - status: show - }); - } - }, - methods: { - changeStatus() { - this.setData({ - status: true - }); - if (this.data.timer) clearTimeout(this.data.timer); - this.data.timer = setTimeout(() => { - this.setData({ - status: false - }); - if (this.data.success) this.data.success(); - this.data.timer = null; - }, this.properties.duration); - } - } -}); \ No newline at end of file +export default Behavior({observers:{show:function(t){t&&this.changeStatus(),t||this.setData({status:t})}},methods:{changeStatus(){this.setData({status:!0}),this.data.timer&&clearTimeout(this.data.timer),this.data.timer=setTimeout(()=>{this.setData({status:!1}),this.data.success&&this.data.success(),this.data.timer=null},this.properties.duration)}}}); \ No newline at end of file diff --git a/dist/behaviors/zIndex.js b/dist/behaviors/zIndex.js index 3e3d9413..4a804e41 100644 --- a/dist/behaviors/zIndex.js +++ b/dist/behaviors/zIndex.js @@ -1,10 +1 @@ -// eslint-disable-next-line no-undef -export default Behavior({ - behaviors: [], - properties: { - zIndex:{ - type: Number, - value: 777 - } - } -}); \ No newline at end of file +export default Behavior({behaviors:[],properties:{zIndex:{type:Number,value:777}}}); \ No newline at end of file diff --git a/dist/button/index.js b/dist/button/index.js index 201ca036..3cb04616 100644 --- a/dist/button/index.js +++ b/dist/button/index.js @@ -1,78 +1 @@ -Component({ - externalClasses: ['l-class', 'l-hover-class', 'l-img-class','l-icon-class'], - properties: { - // button组建标识 - name: { - type: String, - value: 'lin' - }, - type: { - type: String, - value: 'default', - }, - plain: Boolean, - size: { - type: String, - value: 'medium', - }, - shape: { - type: String, - value: 'circle', - }, - disabled: { - type: Boolean, - value: false, - }, - special: { - type: Boolean, - value: false, - }, - loading: { - type: Boolean, - value: false, - }, - // 微信原生接口 - width: Number, - height: Number, - icon: String, - image: String, - bgColor: String, - iconColor: String, - iconSize: String, - openType: String, - appParameter: String, - lang: String, - hoverStopPropagation: Boolean, - hoverStartTime: { - type: Number, - value: 20 - }, - hoverStayTime: { - type: Number, - value: 70 - }, - sessionFrom: { - type: String, - value: '' - }, - sendMessageTitle: String, - sendMessagePath: String, - sendMessageImg: String, - showMessageCard: Boolean, - formType: String - }, - methods: { - // button点击事件 - handleTap() { - if (this.data.disabled || this.data.loading) return false; - this.triggerEvent('lintap', {}, { - bubbles: true, - composed: true - }); - }, - // 开放能力事件回调 - openTypeEvent(data) { - this.triggerEvent(data.type, data.detail, {}); - } - } -}); +Component({externalClasses:["l-class","l-label-class","l-hover-class","l-img-class","l-icon-class"],properties:{name:{type:String,value:"lin"},type:{type:String,value:"default"},plain:Boolean,size:{type:String,value:"medium"},shape:{type:String,value:"circle"},disabled:{type:Boolean,value:!1},special:{type:Boolean,value:!1},loading:{type:Boolean,value:!1},width:Number,height:Number,icon:String,image:String,bgColor:String,iconColor:String,iconSize:String,openType:String,appParameter:String,lang:String,hoverStopPropagation:Boolean,hoverStartTime:{type:Number,value:20},hoverStayTime:{type:Number,value:70},sessionFrom:{type:String,value:""},sendMessageTitle:String,sendMessagePath:String,sendMessageImg:String,showMessageCard:Boolean,formType:String},methods:{handleTap(){if(this.data.disabled||this.data.loading)return!1;this.triggerEvent("lintap",{},{bubbles:!0,composed:!0})},openTypeEvent(e){this.triggerEvent(e.type,e.detail,{})}}}); \ No newline at end of file diff --git a/dist/button/index.json b/dist/button/index.json index c01e2d7e..e11651a3 100644 --- a/dist/button/index.json +++ b/dist/button/index.json @@ -1,6 +1 @@ -{ - "component": true, - "usingComponents": { - "l-icon":"../icon/index" - } -} \ No newline at end of file +{"component":true,"usingComponents":{"l-icon":"../icon/index"}} \ No newline at end of file diff --git a/dist/button/index.wxml b/dist/button/index.wxml index f8079c23..81fba9c5 100644 --- a/dist/button/index.wxml +++ b/dist/button/index.wxml @@ -1,39 +1,16 @@ -