1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
function preview1(e) { uni.previewImage({ urls: [e], }) }
function preview2(e, q) { uni.previewImage({ urls: e, current: q, indicator: 'number', }) }
function previewLB(e) { uni.previewImage({ urls: [getApp().globalData.baseUrl + e.image], }) }
function loading() { uni.showLoading({ title: '努力加载中~', mask: true, }) }
function img(e) { return getApp().globalData.baseUrl + e }
function changeBank(e) { console.log(e) e = '' + e var ary = e.split('') ary.splice(4, 12, ' **** **** **** ') var num = ary.join('') return num }
import Vue from 'vue' Date.prototype.Format = function (fmt) { var o = { 'M+': this.getMonth() + 1, 'D+': this.getDate(), 'h+': this.getHours(), 'm+': this.getMinutes(), 's+': this.getSeconds(), 'q+': Math.floor((this.getMonth() + 3) / 3), S: this.getMilliseconds(), } if (/(Y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length)) for (var k in o) if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)) return fmt } const formatTime = function (times, pattern) { var d = new Date(times).Format('YYYY-MM-DD hh:mm:ss') if (pattern) { d = new Date(times).Format(pattern) } return d.toLocaleString() }
function num(e) { if (e > 9999) { return '9999+' } else { return e } }
function toast(icon, text, duration = 1500, mask = false, position = 'bottom') { uni.showToast({ icon: icon, title: text, duration: duration, mask: mask, position: position, }) }
function changeTime(value) { let result = parseInt(value) let m = Math.floor((result / 60) % 60) < 10 ? '0' + Math.floor((result / 60) % 60) : Math.floor((result / 60) % 60) let s = Math.floor(result % 60) < 10 ? '0' + Math.floor(result % 60) : Math.floor(result % 60) result = `${m}:${s}` return result }
function uploadImage(callback) { uni.chooseImage({ success: res => { const tempFilePaths = res.tempFilePaths uni.showLoading({ title: '上传中', mask: true, }) uni.uploadFile({ url: getApp().globalData.baseUrl + '/api/video.Video/qiniu', filePath: tempFilePaths[0], name: 'file', success: res => { console.log(JSON.parse(res.data)) if (JSON.parse(res.data).code == 1) { callback(JSON.parse(res.data).data.url) } else { uni.showToast({ title: JSON.parse(res.data).msg, mask: true, }) } }, complete: () => { uni.hideLoading() }, }) }, }) }
function uploadImage2(success, count = 9) { uni.chooseImage({ count: count, success: res => { uni.showLoading({ title: '上传中', mask: true, }) console.log(res) if (res.tempFilePaths.length > count) { uni.showToast({ icon: 'none', title: `最多上传${count}张图片`, duration: 2000, }) } else { var imgList = [] for (let k = 0; k < res.tempFilePaths.length; k++) { uni.uploadFile({ url: getApp().globalData.baseUrl + '/api/video.Video/qiniu', filePath: res.tempFilePaths[k], name: 'file', fileType: 'image', success: res => { uni.hideLoading() if (JSON.parse(res.data).code == 1) { console.log('上传成功', JSON.parse(res.data)) let url_href = JSON.parse(res.data).data.url imgList.push(url_href) success(imgList) } else { uni.showToast({ title: JSON.parse(res.data).msg, mask: true, }) } }, complete: () => { uni.hideLoading() }, }) } } }, }) }
function changeList(e) { if (e == null || e == '') { return [] } else { return e.split(',') } }
function splitTime(e) { if (e) { return e.split(' ')[0] } }
function validate(obj) { var reg = /^[0-9]*$/ return reg.test(obj) }
export default { validate, preview1, preview2, previewLB, img, formatTime, changeBank, num, toast, changeTime, changeList, splitTime, uploadImage, uploadImage2, loading, }
|