123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /* 常用工具函数 */
- export const msg = (title, duration = 1500, mask = true, icon = 'none') => {
- //统一提示方便全局修改
- if (Boolean(title) === false) { return }
- uni.showToast({
- title,
- duration,
- mask,
- icon
- })
- }
- export const modal = (title, content, confirmText, cancelText, showCancel = false, callBack) => {
- uni.showModal({
- title,
- content,
- confirmText,
- cancelText,
- confirmColor: '#E15616',
- showCancel,
- success: function(res) {
- if (res.confirm) {
- callBack()
- }
- }
- })
- }
- export const json = type => {
- //模拟异步请求数据
- return new Promise(resolve => {
- setTimeout(() => {
- // console.log(resolve+'======='+type);
- resolve(Json[type])
- }, 500)
- })
- }
- export const prePage = () => {
- let pages = getCurrentPages()
- let prePage = pages[pages.length - 2]
- // #ifdef H5
- return prePage
- // #endif
- return prePage.$vm
- }
- // 获取节点元素信息
- export const boundingClientRect = (component, selector, flag = false) => {
- return new Promise((resolve, reject) => {
- const query = uni.createSelectorQuery().in(component)
- if (!flag) {
- query
- .select(selector)
- .boundingClientRect(data => {
- resolve(data)
- })
- .exec()
- } else {
- query
- .selectAll(selector)
- .boundingClientRect(data => {
- resolve(data)
- })
- .exec()
- }
- })
- }
|