hlsPopup.js 9.3 KB
Newer Older
李晓兵's avatar
李晓兵 committed
1 2
import Vue from 'vue'
import {ToastPlugin, AlertPlugin, ConfirmPlugin, LoadingPlugin, DatetimePlugin} from 'vux'
JingChao's avatar
JingChao committed
3
import {ActionSheetPlugin, ShowPicturePlugin, SelectPlugin, NotifyPlugin, NumberKeyboardPlugin} from 'hls-easy-ui'
李晓兵's avatar
李晓兵 committed
4 5 6 7 8
Vue.use(ToastPlugin)
Vue.use(AlertPlugin)
Vue.use(ConfirmPlugin)
Vue.use(LoadingPlugin)
Vue.use(DatetimePlugin)
JingChao's avatar
JingChao committed
9 10 11 12 13
Vue.use(ActionSheetPlugin)
Vue.use(ShowPicturePlugin)
Vue.use(SelectPlugin)
Vue.use(NumberKeyboardPlugin)
Vue.use(NotifyPlugin)
李晓兵's avatar
李晓兵 committed
14 15 16 17 18 19

export default {

  isLoading: false,
  SHOW_TIMES: 2000,
  IS_SHOW_MASK: true,
李晓兵's avatar
李晓兵 committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  /**
   * 移除数组的某个元素
   * @param dx 下标
   * @returns {boolean}
   */
  remove: function (dx) {
    debugger
    if (isNaN(dx) || dx > this.length) {
      return false
    }
    for (var i = 0, n = 0; i < this.length; i++) {
      if (this[i] != this[dx]) {
        this[n++] = this[i]
      }
    }
    this.length -= 1
  },
李晓兵's avatar
李晓兵 committed
37 38 39 40 41 42
  /**
   * 锁屏函数 超过10s后自动解屏用于防止屏幕锁死
   * 自动截屏成弹出错误提示框
   * @param content 锁屏内容
   */
  showLoading: function (content) {
JingChao's avatar
JingChao committed
43
    let vm = this
李晓兵's avatar
李晓兵 committed
44
    Vue.$vux.loading.show({
JingChao's avatar
JingChao committed
45
      text: content || 'Loading',
李晓兵's avatar
李晓兵 committed
46
    })
JingChao's avatar
JingChao committed
47 48
    this.isLoading = true
    // 10s后自动解屏用于防止屏幕锁死
李晓兵's avatar
李晓兵 committed
49 50
    setTimeout(() => {
      if (vm.isLoading) {
JingChao's avatar
JingChao committed
51 52 53 54
        Vue.$vux.loading.hide()
        vm.isLoading = false
        // 弹出操作失败
        /* Vue.$vux.toast.show({
李晓兵's avatar
李晓兵 committed
55
          text: '操作失败',
JingChao's avatar
JingChao committed
56
          type: 'warn',
李晓兵's avatar
李晓兵 committed
57 58
          time: vm.SHOW_TIMES,
          isShowMask: vm.IS_SHOW_MASK,
JingChao's avatar
JingChao committed
59 60
          position: 'middle',
        }) */
李晓兵's avatar
李晓兵 committed
61
      }
JingChao's avatar
JingChao committed
62
    }, 40000)
李晓兵's avatar
李晓兵 committed
63 64 65 66 67 68
  },
  /**
   * 隐藏
   */
  hideLoading: function () {
    Vue.$vux.loading.hide()
JingChao's avatar
JingChao committed
69
    this.isLoading = false
李晓兵's avatar
李晓兵 committed
70 71 72 73 74 75 76
  },

  /**
   * 长时间顶部提示toast
   * @param content
   */
  showLongTop: function (content) {
JingChao's avatar
JingChao committed
77 78 79 80 81 82 83 84 85
    let vm = this
    let text = content || '操作失败'
    Vue.$vux.toast.show({
      text: text,
      type: 'text',
      time: vm.SHOW_TIMES,
      isShowMask: vm.IS_SHOW_MASK,
      position: 'top',
    })
李晓兵's avatar
李晓兵 committed
86 87 88 89 90 91 92
  },

  /**
   * 长时间中部提示toast
   * @param content
   */
  showLongCenter: function (content) {
JingChao's avatar
JingChao committed
93
    let vm = this
李晓兵's avatar
李晓兵 committed
94 95 96
    //let text = content || '操作失败'
    let imgUrl = require('../assets/image/waring.png')
    let text = '<div><img src=' + imgUrl + '></div>' + content
JingChao's avatar
JingChao committed
97 98 99 100 101 102 103
    Vue.$vux.toast.show({
      text: text,
      type: 'text',
      time: vm.SHOW_TIMES,
      isShowMask: vm.IS_SHOW_MASK,
      position: 'middle',
    })
李晓兵's avatar
李晓兵 committed
104 105 106 107 108 109
  },
  /**
   * 长时间中部提示toast
   * @param content
   */
  showLongBottom: function (content) {
JingChao's avatar
JingChao committed
110 111 112 113 114 115 116 117 118
    let vm = this
    let text = content || '操作失败'
    Vue.$vux.toast.show({
      text: text,
      time: vm.SHOW_TIMES,
      type: 'text',
      isShowMask: vm.IS_SHOW_MASK,
      position: 'bottom',
    })
李晓兵's avatar
李晓兵 committed
119 120 121 122 123 124
  },
  /**
   * 成功提示框
   * @param content
   */
  showSuccess: function (content) {
JingChao's avatar
JingChao committed
125
    let vm = this
李晓兵's avatar
李晓兵 committed
126 127 128 129
    Vue.$vux.toast.show({
      text: content || '操作成功',
      time: vm.SHOW_TIMES,
      isShowMask: vm.IS_SHOW_MASK,
JingChao's avatar
JingChao committed
130 131
      type: 'success',
      position: 'middle',
李晓兵's avatar
李晓兵 committed
132 133 134 135 136 137 138
    })
  },
  /**
   * 成功提示框
   * @param content
   */
  showError: function (content) {
JingChao's avatar
JingChao committed
139
    let vm = this
李晓兵's avatar
李晓兵 committed
140 141
    Vue.$vux.toast.show({
      text: content || '操作失败',
JingChao's avatar
JingChao committed
142
      type: 'warn',
李晓兵's avatar
李晓兵 committed
143 144
      isShowMask: vm.IS_SHOW_MASK,
      time: vm.SHOW_TIMES,
JingChao's avatar
JingChao committed
145
      position: 'middle',
李晓兵's avatar
李晓兵 committed
146 147 148 149 150 151 152 153 154
    })
  },
  /**
   * 弹出是否确认的窗口
   * @param confirmObject.title 标题
   * @param confirmObject.content 内容
   * @param confirmObject.onConfirm 确定函数
   */
  showConfirm: function (confirmObject) {
JingChao's avatar
JingChao committed
155 156 157 158 159 160 161 162 163 164 165
    let def = {
      title: confirmObject.title || '提示',
      content: confirmObject.content || '',
      confirmText: '确定',
      cancelText: '取消',
      onConfirm: () => {
        confirmObject.onConfirm(1)
      },
      onCancel: () => {
        confirmObject.onConfirm(0)
      },
李晓兵's avatar
李晓兵 committed
166
    }
JingChao's avatar
JingChao committed
167
    Vue.$vux.confirm.show(def)
李晓兵's avatar
李晓兵 committed
168 169 170 171 172 173 174 175 176
  },
  /*
   * 弹出确认的窗口
   * @param confirmObject.title 标题
   * @param confirmObject.content 内容
   * @param confirmObject.onConfirm 确定函数
   *
   */
  showPopup: function (confirmObject) {
JingChao's avatar
JingChao committed
177 178 179 180 181 182 183 184
    let def = {
      title: confirmObject.title || '提示',
      content: confirmObject.content || '',
      confirmText: '确定',
      showCancelButton: false,
      onConfirm: () => {
        confirmObject.onConfirm()
      },
李晓兵's avatar
李晓兵 committed
185
    }
JingChao's avatar
JingChao committed
186
    Vue.$vux.confirm.show(def)
李晓兵's avatar
李晓兵 committed
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
  },
  /**
   * @param actionObject.titleText 弹出框的标题可空
   * @param actionObject.callback 点击按钮的回调函数 回传buttonArray数组下标
   * @param actionObject.buttonArray 按钮数组支持[string,string],[object,object],
   *        当为后一种是 object为{text:'拍照',type:'primary'},type支持 primary,warn,disabled
   *
   *  {
   *      titleText: '照片',
   *      buttonArray: [{text:'拍照',type:'warn'}, {text:'从相册取',type:'primary'}],
   *      callback: (index) => {
   *        alert(index);
   *      }
   *   }
   *
   *    {
   *      buttonArray: ['拍照','从相册取'],
   *      callback: (index) => {
   *        alert(index);
   *      }
   *   }
   *
   */
  showActionSheet: function (actionObject) {
    if (typeof actionObject === 'object') {
JingChao's avatar
JingChao committed
212
      let buttons = []
李晓兵's avatar
李晓兵 committed
213 214 215 216 217
      for (let i = 0; i < actionObject.buttonArray.length; i++) {
        if (typeof actionObject.buttonArray[i] === 'object') {
          buttons.push({
            text: actionObject.buttonArray[i].text,
            type: actionObject.buttonArray[i].type,
JingChao's avatar
JingChao committed
218
            callback: actionObject.callback,
李晓兵's avatar
李晓兵 committed
219 220 221 222
          })
        } else {
          buttons.push({
            text: actionObject.buttonArray[i],
JingChao's avatar
JingChao committed
223
            callback: actionObject.callback,
李晓兵's avatar
李晓兵 committed
224 225 226
          })
        }
      }
JingChao's avatar
JingChao committed
227
      ActionSheetPlugin.show({
李晓兵's avatar
李晓兵 committed
228
        title: actionObject.titleText || '',
JingChao's avatar
JingChao committed
229
        buttons: buttons,
李晓兵's avatar
李晓兵 committed
230 231 232 233 234 235 236 237 238 239 240 241
      })
    }
  },

  /**
   * 时间选择函数
   * @param timeObject.nowDate 当前展示的时间 可不填
   * @param timeObject.format 时间格式支持不支持秒
   * @param timeObject.callback 点击确定的回调函数
   *
   */
  showTime: function (timeObject) {
JingChao's avatar
JingChao committed
242 243
    let date = new Date().format('yyyy-MM-dd')
    let format = 'YYYY-MM-DD'
李晓兵's avatar
李晓兵 committed
244 245 246 247 248 249 250 251 252 253 254 255 256
    if (timeObject.nowDate) {
      date = timeObject.nowDate
    }
    if (timeObject.format) {
      format = timeObject.format
    }
    Vue.$vux.datetime.show({
      cancelText: '取消',
      confirmText: '确定',
      minYear: '1900',
      maxYear: '2200',
      format: format,
      value: date,
JingChao's avatar
JingChao committed
257 258 259
      onConfirm (val) {
        timeObject.callback(val)
      },
李晓兵's avatar
李晓兵 committed
260 261 262 263 264 265 266 267
    })
  },
  /**
   * 图片放大预览
   * @param imgObject.imgUrl
   */
  showBigPicture: function (imgObject) {
    if (typeof imgObject === 'object') {
JingChao's avatar
JingChao committed
268
      ShowPicturePlugin.show({
李晓兵's avatar
李晓兵 committed
269
        imgUrl: imgObject.imgUrl,
JingChao's avatar
JingChao committed
270
        width: imgObject.width,
李晓兵's avatar
李晓兵 committed
271 272 273 274
      })
    }
  },

李晓兵's avatar
李晓兵 committed
275

李晓兵's avatar
李晓兵 committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
  /**
   * 下拉框 支持级联操作 需指定 parent 属性
   * @param selectOption.list Array [{"code": "NP","code_name": "个人"}]
   * @param selectOption.code String "bp_type"
   * @param selectOption.object Object 当前数据对象
   * @param selectOption.returnItem function 回调函数返回index与object
   * var bp_class_list = [
   *    {
   *      "code": "NP",
   *      "code_name": "个人"
   *    },{
   *       "code": "NP1",
   *       "code_name": "个人1"
   *     }];
   *  hlsPopup.selectList({
   *     list: bp_class_list,
   *     code: 'bp_type',
   *     object: {},
   *     returnItem: function (index, obj) {
   *        console.log(obj)
   *      }
   *   })
   *
   */
  selectList: function (selectOption) {
    if (typeof selectOption === 'object') {
JingChao's avatar
JingChao committed
302 303
      let list = []
      let length = selectOption.list.length
李晓兵's avatar
李晓兵 committed
304 305 306 307
      vum.forEach(selectOption.list, function (date, index, array) {
        list.push({
          value: date.code,
          name: date.code_name,
JingChao's avatar
JingChao committed
308
          parent: date.parent,
李晓兵's avatar
李晓兵 committed
309 310
        })
        if (index === (length - 1)) {
JingChao's avatar
JingChao committed
311
          SelectPlugin.show({
李晓兵's avatar
李晓兵 committed
312 313 314
            list: list,
            callBack: selectOption.returnItem,
            code: selectOption.code,
JingChao's avatar
JingChao committed
315
            object: selectOption.object,
李晓兵's avatar
李晓兵 committed
316 317
          })
        }
JingChao's avatar
JingChao committed
318
      })
李晓兵's avatar
李晓兵 committed
319 320 321 322 323 324 325 326 327 328 329
    }
  },
  /**
   * 弹出数字键盘
   * @param keyboardObject.title 键盘的title
   * @param keyboardObject.closeButtonText 键盘的关闭按钮文字
   * @param keyboardObject.keyDown 普通按键按下去事件
   * @param keyboardObject.keyDelete 删除按键按下去事件
   */
  showNumberKeyborad: function (keyboardObject) {
    if (typeof keyboardObject === 'object') {
JingChao's avatar
JingChao committed
330
      NumberKeyboardPlugin.show({
李晓兵's avatar
李晓兵 committed
331 332 333 334 335 336 337 338
        title: keyboardObject.title,
        closeButtonText: keyboardObject.closeButtonText,
        extraKey: keyboardObject.extraKey || '.',
        keyDown: function (text) {
          keyboardObject.keyDown(text)
        },
        keyDelete: function () {
          keyboardObject.keyDelete()
JingChao's avatar
JingChao committed
339 340
          // console.log('delete')
        },
李晓兵's avatar
李晓兵 committed
341 342 343 344 345 346 347 348 349 350 351 352
      })
    }
  },
  /**
   * 弹出Notify
   * @param notifyObject.content 内容
   * @param notifyObject.position 位置
   * @param notifyObject.time 显示时长
   * @param notifyObject.type 类型  success warning default
   */
  showNotify: function (notifyObject) {
    if (typeof notifyObject === 'object') {
JingChao's avatar
JingChao committed
353
      NotifyPlugin.show({
李晓兵's avatar
李晓兵 committed
354 355 356 357
        show: true,
        content: notifyObject.content,
        position: notifyObject.position || 'top',
        time: notifyObject.time || 3000,
JingChao's avatar
JingChao committed
358
        type: notifyObject.type || 'default',
李晓兵's avatar
李晓兵 committed
359 360
      })
    }
JingChao's avatar
JingChao committed
361
  },
李晓兵's avatar
李晓兵 committed
362
}