xiaohaizhao 1 سال پیش
والد
کامیت
9ae9748d5c
6فایلهای تغییر یافته به همراه345 افزوده شده و 0 حذف شده
  1. 57 0
      utils/Http.js
  2. 35 0
      utils/Socket.js
  3. 80 0
      utils/api.js
  4. 28 0
      utils/auth.js
  5. 34 0
      utils/basicInspection.js
  6. 111 0
      utils/tool.js

+ 57 - 0
utils/Http.js

@@ -0,0 +1,57 @@
+class HTTP {
+    constructor({
+        baseUrl
+    }) {
+        this.baseUrl = baseUrl;
+    }
+    request({
+        url,
+        data = {},
+        method = "POST",
+        header = {
+            'content-type': 'application/json'
+        },
+        showLoading = ''
+    }) {
+        return new Promise((resolve, reject) => {
+            this._request(url, resolve, reject, data, method, header, showLoading);
+        })
+    }
+    _request(url, resolve, reject, data, method, header, showLoading) {
+        if (showLoading) uni.showLoading({
+            title: showLoading,
+            mask: true
+        })
+        uni.request({
+            url: this.baseUrl + '/yos/rest' + url,
+            data: data,
+            method: method,
+            header: header,
+            timeout: 60000,
+            success: res => resolve(res.data),
+            fial: err => reject(err),
+            complete: (res) => {
+                if (showLoading) uni.hideLoading()
+                if (res.errMsg != 'request:ok') {
+                    uni.showToast({
+                        title: '网络异常,请稍后再试',
+                        icon: "none"
+                    })
+                } else if (res.data.msg == '登陆状态已过期,请重新登陆!') {
+                    uni.redirectTo({
+                        url: '/pages/login/login',
+                        success() {
+                            uni.showToast({
+                                title: res.msg,
+                                icon: "none"
+                            })
+                        }
+                    });
+                }
+            }
+        })
+    }
+}
+export {
+    HTTP
+}

+ 35 - 0
utils/Socket.js

@@ -0,0 +1,35 @@
+class Socket {
+    constructor({
+        socket
+    }) {
+        this.baseUrl = socket;
+        this.socketEstablish = false; //是否建立链接
+        this.socketCallback = () => {
+
+        };
+    }
+    initSocket() {
+        this.SocketTask = uni.connectSocket({
+            url: this.baseUrl + '/waserver/webSocket/' + uni.getStorageSync('userMsg').token,
+            complete: (res) => {
+                console.log(res)
+            }
+        })
+        this.SocketTask.onOpen(function (res) {
+            this.socketEstablish = true;
+        })
+        this.SocketTask.onMessage(function (res) {
+            // this.socketCallback(res)
+            this.$Http.updateMessage && this.$Http.updateMessage()
+        })
+        this.SocketTask.onError(function (res) {
+            this.socketEstablish = false;
+        })
+        this.SocketTask.onClose(function (res) {
+            this.socketEstablish = false;
+        })
+    }
+}
+export {
+    Socket
+}

+ 80 - 0
utils/api.js

@@ -0,0 +1,80 @@
+import {
+    HTTP
+} from './Http.js'
+class ApiModel extends HTTP {
+    devicevaluecheck(data) {
+        data.accesstoken = wx.getStorageSync('userMsg').token;
+        return this.request({
+            url: "/simple/devicevaluecheck",
+            data
+        })
+    }
+    loginbywechat(data) {
+        return this.request({
+            url: "/index/loginbywechat",
+            data
+        })
+    }
+    /* 登录 */
+    login(data) {
+        return this.request({
+            url: "/index/loginbyaccount",
+            data
+        })
+    }
+    /* 验证码登录 */
+    plogin(data) {
+        return this.request({
+            url: "/index/login",
+            data
+        })
+    }
+    /* 获取验证码 */
+    getpassword(data) {
+        return this.request({
+            url: "/index/getpassword",
+            data
+        })
+    }
+    /* 有状态通用 */
+    basic(data, loading = true) {
+        data.accesstoken = wx.getStorageSync('userMsg').token;
+        return this.request({
+            url: "/index",
+            data,
+            loading
+        })
+    }
+    /* 无状态 */
+    base(data, loading = true) {
+        return this.request({
+            url: "/index",
+            data,
+            loading
+        })
+    }
+    /* 退出登录 */
+    logout() {
+        let data = {
+            accesstoken: wx.getStorageSync('userMsg').token
+        }
+        return this.request({
+            url: "/index/logout",
+            data
+        })
+    }
+    /* 获取地区code */
+    getLocationCode() {
+        return this.request({
+            url: "/index/getforward?url=" + encodeURIComponent("http://www.nmc.cn/rest/position"),
+            data: {},
+            method: "GET",
+            header: {
+                "Access-Control-Allow-Origin": "*"
+            }
+        })
+    }
+}
+export {
+    ApiModel
+}

+ 28 - 0
utils/auth.js

@@ -0,0 +1,28 @@
+function parsingAuth(list) {
+    let authList = {}
+    list.forEach(system => {
+        // let systemObj = {}
+        system.modules.forEach(app => {
+            let appObj = {}
+            app.apps.forEach(m => {
+                appObj[m.meta.title] = {
+                    path: m.path,
+                    pathDetail: m.path_index,
+                    pathDetail: m.path_index,
+                    name: m.name,
+                    remark: m.meta.title,
+                    cover: m.cover,
+                    option: m.meta.auth.map(v => v.option),
+                    optionname: m.meta.auth.map(v => v.optionname)
+                }
+            })
+            // systemObj[app.systemmodulename] = appObj;
+            authList[app.systemmodulename] = appObj;
+        })
+        // authList[system.systemname] = systemObj;
+    });
+    uni.setStorageSync('authList', authList)
+}
+module.exports = {
+    parsingAuth
+}

+ 34 - 0
utils/basicInspection.js

@@ -0,0 +1,34 @@
+/* 去除字符串中的特殊符号 */
+const queryStr = (str, title = '该符号不可输入!') => {
+    const pattern = new RegExp(/[`$%^&()\=<>"{}|\/;'\\[\]·%……&——\={}|]/g);
+    if (pattern.test(str) == true && title) wx.showToast({
+        title,
+        icon: "none"
+    })
+    return str.replace(pattern, '');
+}
+/* 校验手机号码 */
+const CheckPhoneNumber = (num, title = '请输入正确的11位手机号码!') => {
+    const reg = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/;
+    let isAllow = reg.test(num);
+    if (!isAllow && title) wx.showToast({
+        title,
+        icon: "none"
+    })
+    return isAllow;
+}
+/* 校验邮箱 */
+const CheckEmail = (num, title = '请输入正确的邮箱格式!') => {
+    const reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
+    let isAllow = reg.test(num);
+    if (!isAllow && title) wx.showToast({
+        title,
+        icon: "none"
+    })
+    return isAllow;
+}
+module.exports = {
+    queryStr,
+    CheckPhoneNumber,
+    CheckEmail
+}

+ 111 - 0
utils/tool.js

@@ -0,0 +1,111 @@
+import Vue from 'vue'
+
+function mount() {
+    Vue.prototype.getLocation = (isReverseGeocoder = false) => {
+        return new Promise((resolve, reject) => {
+            let that = this;
+            handle()
+
+            function handle() {
+                uni.getLocation({
+                    altitude: true,
+                    highAccuracyExpireTime: 8000,
+                    isHighAccuracy: true,
+                    success: res => {
+                        console.log("获取定位", res)
+                        if (isReverseGeocoder) {
+                            Vue.prototype.$Http.basic({
+                                "id": "10027201",
+                                "content": {
+                                    "lon": res.longitude,
+                                    "lat": res.latitude
+                                }
+                            }).then(s => {
+                                console.log("定位", s)
+                                res.result = s.data.result;
+                                resolve(res)
+                            })
+                        } else {
+                            resolve(res)
+                        }
+                    },
+                    fail: err => {
+                        uni.hideLoading();
+                        query()
+                    }
+                })
+            }
+
+            function query() {
+                uni.getSetting({
+                    success({
+                        authSetting
+                    }) {
+                        if (authSetting['scope.userLocation']) {
+                            handle()
+                        } else {
+                            uni.showModal({
+                                title: '提示',
+                                content: '您未开启地理位置授权',
+                                cancelText: '下次再说',
+                                confirmText: '前去授权',
+                                success: ({
+                                    confirm
+                                }) => {
+                                    if (confirm) {
+                                        uni.openSetting({
+                                            success(res) {
+                                                if (res.authSetting['scope.userLocation']) handle();
+                                            }
+                                        })
+                                    } else {
+                                        uni.showToast({
+                                            title: "已拒绝地理位置授权",
+                                            icon: "none",
+                                        })
+                                    }
+                                }
+                            })
+                        }
+                    }
+                })
+            }
+        })
+    };
+    Vue.prototype.cutoff = (msg, title = "", mask = false, exitTime = 0, icon = 'none', duration = 2000, ) => {
+        if (msg != '成功' || title) uni.showToast({
+            title: msg == '成功' ? title : msg,
+            duration,
+            icon,
+            mask: mask || exitTime != 0
+        })
+        if (exitTime && msg == '成功') setTimeout(uni.navigateBack, exitTime)
+        return msg != '成功';
+    };
+    Vue.prototype.paging = (content, init) => {
+        if (content.pageTotal == undefined || !content.pageTotal) content.pageTotal = 1;
+        if (content.pageNumber == undefined || !content.pageNumber) content.pageNumber = 1;
+        if (content.pageSize == undefined || !content.pageSize) content.pageSize = 20;
+        if (init) content.pageNumber = 1;
+        return content.pageNumber > content.pageTotal;
+    }
+    Vue.prototype.tovw = (num) => (num * 100 / 375).toFixed(3) + "vw";
+    Vue.prototype.getApps = appRemark => Object.values(uni.getStorageSync('authList')[appRemark]);
+    Vue.prototype.getHeight = (even, that, calculate = true) => {
+        return new Promise((resolve, reject) => {
+            if (calculate) {
+                uni.getSystemInfo({
+                    success(s) {
+                        uni.createSelectorQuery().in(that).select(even).boundingClientRect().exec(res => (!res[0]) ? reject('没有查询到元素') : resolve(s.windowHeight - res[0].bottom))
+                    }
+                });
+            } else {
+                uni.createSelectorQuery().in(that).select(even).boundingClientRect().exec(res => (!res[0]) ? reject('没有查询到元素') : resolve(res[0]))
+            }
+        })
+    };
+}
+
+module.exports = {
+    mount
+}