import Vue from 'vue' Vue.use( { install(Vue){ Vue.prototype.$dialog = function(content, title, type, duration, width, height, vbind) { if(typeof content == 'string') { let vtitle = type==='Success'? `${title}` : title if(type==='Error') vtitle = `${title}` let data = {id: this.$id(), component: `dialog/${type || 'Info'}`, vbind: {content: content, duration: duration, vbind: vbind}, title: vtitle, width: width || '500px', height: height || '100px'} this.$store.commit('updateStore', {name: 'showmodal', data: data}) } else this.$store.commit('updateStore', {name: 'showmodal', data: content}) } Vue.prototype.$snackbar = function(content, title, type, width, height) { if(typeof content == 'string') { let vtitle = type==='Success'? `${title}` : title if(type==='Error') vtitle = `${title}` let data = {id: this.$id(), component: `snackbar/${type || 'Info'}`, vbind: {content: content}, title: vtitle, width: width || '400px', height: height || '100px'} this.$store.commit('updateStore', {name: 'snackbar', data: data}) } else this.$store.commit('updateStore', {name: 'snackbar', data: content}) } Vue.prototype.$pending = function() { this.$dialog({width: '500px', icon: ' mdi mdi-wrench-clock', content: '
Chức năng này đang được xây dựng, vui lòng trở lại sau
', type: 'is-dark', progress:true, duration: 5}) } Vue.prototype.$getLink = function(val) { if(val === undefined || val === null || val === '' || val==="") return '' let json = val.indexOf('{')>=0? JSON.parse(val) : {path: val} return json } Vue.prototype.$timeFormat = function(startDate, endDate) { let milliseconds = startDate - endDate let secs = Math.floor(Math.abs(milliseconds) / 1000); let mins = Math.floor(secs / 60); let hours = Math.floor(mins / 60); let days = Math.floor(hours / 24); const millisecs = Math.floor(Math.abs(milliseconds)) % 1000; function pad2(n) { return (n < 10 ? '0' : '') + n } let display = undefined if(days>=1) { display = pad2(startDate.getHours()) + ':' + pad2(startDate.getMinutes()) + ' ' + pad2(startDate.getDate()) + '/' + pad2(startDate.getMonth()) } else if(hours>0) display = hours + 'h trước' else if(mins>0) display = mins + "' trước" else if(secs>0 || millisecs>0) display = 'Vừa xong' return { days: days, hours: hours % 24, minutes: mins % 60, seconds: secs % 60, milliSeconds: millisecs, display: display } } Vue.prototype.$errPhone = function(phone) { var text = undefined if (this.$empty(phone)) { text = 'Số điện thoại di động không được bỏ trống.' } else if (isNaN(phone)) { text = 'Số điện thoại di động không hợp lệ.' } else if(phone.length<9 || phone.length>11) { text = 'Số điện thoại di động phải có từ 9-11 số.' } return text }, Vue.prototype.$errEmail = function(email) { const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ var text = undefined if (this.$empty(email)) { text = 'Email không được bỏ trống.' } else if (!(re.test(String(email).toLowerCase()))) { text = 'Email không hợp lệ.' } return text } Vue.prototype.$errPhoneEmail = function(contact) { const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ var text = undefined if (this.$empty(contact)) { text = 'Số điện thoại di động hoặc Email không được bỏ trống.' } else if (!(re.test(String(contact).toLowerCase()) || !isNaN(contact))) { text = 'Số điện thoại di động hoặc Email không hợp lệ.' } else if(!isNaN(contact) && (contact.length<9 || contact.length>11)) { text = 'Số điện thoại di động không hợp lệ.' } return text } Vue.prototype.$dummy = function(data, count) { let list = this.$copy(data) for (let index = 0; index < count; index++) { if(data.length