123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import store from '@/store'
- import { SET_LOADING } from '@/store/mutation-types'
- export default {
- showLoading(black = true, mask = false) {
- store.commit(SET_LOADING, { show: true, mask, black })
- },
- hideLoading() {
- store.commit(SET_LOADING, { show: false })
- },
- showNotify(type, message, duration = 1500, background = true) {
- if (!store.state.notify) return
- store.state.notify[type]({
- content: message,
- duration: duration,
- background: background
- })
- },
- info(message, duration = 1500, background = true) {
- this.showNotify('info', message, duration, background)
- },
- success(message, duration = 1500, background = true) {
- this.showNotify('success', message, duration, background)
- },
- error(message, duration = 2000, background = true) {
- this.showNotify('error', message, duration, background)
- },
- warn(message, duration = 2000, background = true) {
- this.showNotify('warn', message, duration, background)
- },
- alert(message, callback, title) {
- uni.showModal({
- title: title || '提示',
- showCancel: false,
- content: message,
- success: (res) => {
- if (callback) {
- callback()
- }
- }
- })
- },
- confirm(message, callback, title, buttonName, cancel) {
- var confirmText, cancelText
- if (buttonName) {
- if (buttonName.length == 1) {
- confirmText = buttonName[0]
- } else if (buttonName.length == 2) {
- confirmText = buttonName[0]
- cancelText = buttonName[1]
- }
- }
- uni.showModal({
- title: title || '',
- content: message,
- confirmText: confirmText || '确定',
- cancelText: cancelText || '取消',
- confirmColor: '#16953C',
- success: (res) => {
- if (res.confirm) {
- if (callback) {
- callback()
- }
- } else if (res.cancel) {
- if (cancel) {
- cancel()
- }
- }
- }
- })
- }
- }
|