| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- //app.js
- import wxValidate from 'utils/wxValidate';
- App({
- onLaunch: function () {},
- globalData: {
- userInfo: null,
- httpsUrl: 'https://cgdl.yutingcn.com/',
- // httpsUrlServer: 'http://39.164.159.226:9090', //个人接口地址
- httpsUrlServer:'http://zhyh.hnyulin.com/api/',
- zdzUrlServer:'http://58.246.189.90:30000', //市指导站推送测试接口地址
- openId: '',
- token: '',
- mq: 'Lh20Sys20K',
- mh: 'pre',
- fUserid: '',
- fUsercode: '',
- fPassword: '',
- latitude: '', //经度
- longitude: '', //维度
- wxPhoneNumber:'',
- personnel: true, // 工作人员模块 判断 对象
- msg: {
- // 饼图数据
- ykhd: 1,
- wkhd: 1,
- zkhd: 1,
- sqgy: 1,
- zhgy: 1,
- dwgy: 1,
- },
- orderType: '',
- orderState: '',
- currentTab: '',
- treeObject: {}, // 行道树修改
- pulicObject: {}, // 公共设施修改
- networkAnomalyFlag: null, //网络异常
- planModify: '', // 计划修改(公园)
- planModifyFlag: '', // 计划修改(公园)
- planID: '', // 查询详情用到的ID
- },
- //封装请求方法,用于请求时携带统一的参数
- request: function (data) {
- let that = this;
- if (typeof data.header === 'undefined') {
- data.header = {};
- }
- (data.header.Authorization = 'openId ' + wx.getStorageSync('openId')), //将请求必须的参数放在请求头
- wx.request(data);
- },
- /**
- * 封装wx.request请求
- * method: 请求方式
- * url: 请求地址
- * data: 要传递的参数
- * callback: 请求成功回调函数
- * errFun: 请求失败回调函数
- **/
- // token查看
- tabbarHide() {
- var token = wx.getStorageSync('token');
- if (token) {
- wx.showTabBar();
- } else {
- wx.hideTabBar();
- }
- },
- wxRequest(method, url, data, callback, errFun) {
- wx.request({
- url: url,
- method: method,
- data: data,
- header: {
- 'content-type':method == 'GET'?'application/json':'application/json; charset=utf-8',
- Accept: 'application/json',
- token: wx.getStorageSync('token'),
- fSource: 1,
- },
- dataType: 'json',
- success: function (res) {
- if(res.status == 600){
- wx.showToast({
- title: res.message,
- icon: 'none',
- duration: 2000,
- mask: true,
- });
- setTimeout(() => {
- console.log(12312);
- wx.reLaunch({
- url: '/pages/login/login',
- });
- }, 2000);
- }else{
- callback(res.data);
- }
-
- },
- fail: function (err) {
- errFun(err);
- },
- });
- },
- WxValidate: (rules, messages) => new wxValidate(rules, messages),
- // 转换时间戳
- getTimeStamp(val) {
- return new Date(val).getTime();
- },
- //时间戳转化为日期格式
- transTime(unixtime) {
- var dateTime = new Date(parseInt(unixtime));
- var year = dateTime.getFullYear();
- if (dateTime.getMonth() + 1 < 10) {
- var month = '0' + (dateTime.getMonth() + 1);
- } else {
- var month = dateTime.getMonth() + 1;
- }
- if (dateTime.getDate() < 10) {
- var day = '0' + dateTime.getDate();
- } else {
- var day = dateTime.getDate();
- }
- var now = new Date();
- var now_new = Date.parse(now.toDateString());
- var milliseconds = now_new - dateTime;
- var timeSpanStr = year + '-' + month + '-' + day;
- return timeSpanStr;
- },
- getReq(url, cb) {
- wx.request({
- url: url,
- method: 'get',
- header: {
- Accept: 'application/json',
- 'content-type': 'application/json;charset=UTF-8',
- token: wx.getStorageSync('token'),
- fSource: 1,
- },
- success: function (res) {
- console.log('resss-', res)
- if (res.data.status == 200) {
- return typeof cb == 'function' && cb(res.data);
- } else if (res.data.status == 600) {
- wx.showToast({
- title: res.data.message,
- icon: 'none',
- duration: 2000,
- mask: true,
- });
- setTimeout(() => {
- console.log(12312);
- wx.reLaunch({
- url: '/pages/login/login',
- });
- }, 2000);
- }
- },
- fail: (res) => {
- wx.hideLoading();
- this.networkAnomaly();
- return typeof cb == 'function' && cb(false);
- },
- });
- },
- getReqNew(url, data, cb) {
- wx.request({
- url: url,
- method: 'get',
- header: {
- Accept: 'application/json',
- 'content-type': 'application/json;charset=UTF-8',
- token: wx.getStorageSync('token'),
- fSource: 1,
- },
- data:data || {},
- success: function (res) {
- console.log(res)
- if (res.data.code == 0) {
- return typeof cb == 'function' && cb(res.data);
- } else if (res.data.code == 500) {
- wx.showToast({
- title: res.data.msg,
- icon: 'none',
- duration: 2000,
- mask: true,
- });
- }else if(res.statusCode == 404){
- wx.hideLoading();
- }
- },
- fail: (res) => {
- console.log(res)
- wx.hideLoading();
- this.networkAnomaly();
- return typeof cb == 'function' && cb(false);
- },
- });
- },
- postReq(url, data, cb) {
- wx.request({
- url: url,
- header: {
- Accept: 'application/json',
- 'content-type': 'application/json;charset=UTF-8',
- token: wx.getStorageSync('token'),
- fSource: 1,
- },
- data: {
- data,
- },
- method: 'post',
- success: function (res) {
- if (res.data.status == 200) {
- return typeof cb == 'function' && cb(res.data);
- } else if (res.status == 600) {
- wx.showToast({
- title: res.data.message || '网络错误',
- icon: 'none',
- duration: 2000,
- mask: true,
- });
- setTimeout(() => {
- wx.reLaunch({
- url: '/pages/login/login',
- });
- }, 2000);
- } else {
- wx.showToast({
- title: res.data.message || '网络错误',
- icon: 'none',
- duration: 2000,
- mask: true,
- });
- }
- },
- fail: () => {
- wx.hideLoading();
- this.networkAnomaly();
- return typeof cb == 'function' && cb(false);
- },
- });
- },
- postReqNew(url, data, cb) {
- wx.request({
- url: url,
- header: {
- Accept: 'application/json',
- 'content-type': 'application/json;charset=UTF-8',
- token: wx.getStorageSync('token'),
- fSource: 1,
- },
- data: data,
- method: 'post',
- success: function (res) {
- if (res.data.code == 0) {
- return typeof cb == 'function' && cb(res.data);
- } else if (res.status == 500) {
- wx.showToast({
- title: res.data.msg || '网络错误',
- icon: 'none',
- duration: 2000,
- mask: true,
- });
- // setTimeout(() => {
- // wx.reLaunch({
- // url: '/pages/login/login',
- // });
- // }, 2000);
- } else {
- wx.showToast({
- title: res.data.msg || '网络错误',
- icon: 'none',
- duration: 2000,
- mask: true,
- });
- }
- },
- fail: () => {
- wx.hideLoading();
- this.networkAnomaly();
- return typeof cb == 'function' && cb(false);
- },
- });
- },
- postReqNew2(url, data, cb) {
- wx.request({
- url: url,
- header: {
- Accept: 'application/json',
- 'content-type': 'application/json;charset=UTF-8',
- token: wx.getStorageSync('token'),
- fSource: 1,
- },
- data: data,
- method: 'post',
- success: function (res) {
- return typeof cb == 'function' && cb(res.data);
- },
- fail: () => {
- wx.hideLoading();
- this.networkAnomaly();
- return typeof cb == 'function' && cb(false);
- },
- });
- },
- // 获取字典封装方法
- getDictionaries(data, cb) {
- wx.request({
- url: this.globalData.httpsUrlServer + '/sysdictionaryvalue/selectDictionaryByFlag',
- header: {
- Accept: 'application/json',
- 'content-type': 'application/json;charset=UTF-8',
- token: wx.getStorageSync('token'),
- fSource: 1,
- },
- data: {
- data,
- },
- method: 'post',
- success: function (res) {
- // wx.hideLoading();
- return typeof cb == 'function' && cb(res.data);
- },
- fail: () => {
- // wx.hideLoading();
- // wx.showModal({
- // title: "网络错误",
- // content: "网络出错,请刷新重试",
- // showCancel: false,
- // })
- this.networkAnomaly();
- return typeof cb == 'function' && cb(false);
- },
- });
- },
- // 提示
- toast(title) {
- wx.showToast({
- title: title,
- icon: 'none',
- duration: 2000,
- });
- },
- // 等待
- loading(title = 'loading~') {
- wx.showLoading({
- title: title,
- mask: true,
- });
- },
- // 结束等待
- hideloading() {
- wx.hideLoading();
- },
- // 封装 验证手机号格式 方法
- checkPhone(phone) {
- if (!/^1\d{10}$/.test(phone)) {
- return false; //验证 失败
- } else {
- return true; //验证 成功
- }
- },
- // 封装 验证电话号 方法
- checkTel(tel) {
- if (!/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(tel)) {
- return false;
- } else {
- return true;
- }
- },
- // 封装 获取个人信息的 方法, 中心 或者 公园
- getUserTrue() {
- let url =
- this.globalData.httpsUrlServer + '/sysroleinfo/selectRoleInfoByUserId';
- const p = new Promise((resolve, reject) => {
- wx.request({
- url: url,
- method: 'get',
- header: {
- Accept: 'application/json',
- 'content-type': 'application/json;charset=UTF-8',
- token: wx.getStorageSync('token'),
- fSource: 1,
- },
- success: function (res) {
- resolve(res.data);
- },
- fail: function (err) {
- reject(err);
- },
- });
- });
- return p;
- },
- sendRequest(method, url, data) {
- url = this.globalData.httpsUrlServer + url;
- return new Promise((resolve, reject) => {
- wx.request({
- url,
- method,
- data,
- header: {
- Accept: 'application/json',
- 'content-type': 'application/json;charset=UTF-8',
- token: wx.getStorageSync('token'),
- fSource: 1,
- },
- success: function (res) {
- resolve(res.data);
- },
- fail: function (err) {
- reject(err);
- },
- });
- });
- },
- networkAnomaly() {
- if (!this.globalData.networkAnomalyFlag) {
- this.globalData.networkAnomalyFlag = setTimeout(() => {
- this.globalData.networkAnomalyFlag = null;
- }, 6000);
- wx.showModal({
- title: '网络错误',
- content: '网络出错,请刷新重试',
- showCancel: false,
- });
- }
- },
- });
|