No Description

app.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. //app.js
  2. import wxValidate from 'utils/wxValidate';
  3. App({
  4. onLaunch: function () {},
  5. globalData: {
  6. userInfo: null,
  7. httpsUrl: 'https://cgdl.yutingcn.com/',
  8. // httpsUrlServer: 'https://park.pingok.cn:28080', //实际接口地址
  9. // httpsUrlServer: 'http://192.168.1.15:9090', //个人接口地址
  10. httpsUrlServer: 'http://39.164.159.226:9090', //个人接口地址
  11. // httpsUrlServer:'http://127.0.0.1:9090',
  12. // httpsUrlServer: 'http://chenwg.cn1.utools.club',
  13. // zdzUrlServer:'https://lhyh.lhsr.sh.gov.cn', //市指导站推送线上接口地址
  14. zdzUrlServer:'http://58.246.189.90:30000', //市指导站推送测试接口地址
  15. openId: '',
  16. token: '',
  17. mq: 'Lh20Sys20K',
  18. mh: 'pre',
  19. fUserid: '',
  20. fUsercode: '',
  21. fPassword: '',
  22. latitude: '', //经度
  23. longitude: '', //维度
  24. wxPhoneNumber:'',
  25. personnel: true, // 工作人员模块 判断 对象
  26. msg: {
  27. // 饼图数据
  28. ykhd: 1,
  29. wkhd: 1,
  30. zkhd: 1,
  31. sqgy: 1,
  32. zhgy: 1,
  33. dwgy: 1,
  34. },
  35. orderType: '',
  36. orderState: '',
  37. currentTab: '',
  38. treeObject: {}, // 行道树修改
  39. pulicObject: {}, // 公共设施修改
  40. networkAnomalyFlag: null, //网络异常
  41. planModify: '', // 计划修改(公园)
  42. planModifyFlag: '', // 计划修改(公园)
  43. planID: '', // 查询详情用到的ID
  44. },
  45. //封装请求方法,用于请求时携带统一的参数
  46. request: function (data) {
  47. let that = this;
  48. if (typeof data.header === 'undefined') {
  49. data.header = {};
  50. }
  51. (data.header.Authorization = 'openId ' + wx.getStorageSync('openId')), //将请求必须的参数放在请求头
  52. wx.request(data);
  53. },
  54. /**
  55. * 封装wx.request请求
  56. * method: 请求方式
  57. * url: 请求地址
  58. * data: 要传递的参数
  59. * callback: 请求成功回调函数
  60. * errFun: 请求失败回调函数
  61. **/
  62. // token查看
  63. tabbarHide() {
  64. var token = wx.getStorageSync('token');
  65. if (token) {
  66. wx.showTabBar();
  67. } else {
  68. wx.hideTabBar();
  69. }
  70. },
  71. wxRequest(method, url, data, callback, errFun) {
  72. wx.request({
  73. url: url,
  74. method: method,
  75. data: data,
  76. header: {
  77. 'content-type':method == 'GET'?'application/json':'application/json; charset=utf-8',
  78. Accept: 'application/json',
  79. token: wx.getStorageSync('token'),
  80. fSource: 1,
  81. },
  82. dataType: 'json',
  83. success: function (res) {
  84. if(res.status == 600){
  85. wx.showToast({
  86. title: res.message,
  87. icon: 'none',
  88. duration: 2000,
  89. mask: true,
  90. });
  91. setTimeout(() => {
  92. console.log(12312);
  93. wx.reLaunch({
  94. url: '/pages/login/login',
  95. });
  96. }, 2000);
  97. }else{
  98. callback(res.data);
  99. }
  100. },
  101. fail: function (err) {
  102. errFun(err);
  103. },
  104. });
  105. },
  106. WxValidate: (rules, messages) => new wxValidate(rules, messages),
  107. // 转换时间戳
  108. getTimeStamp(val) {
  109. return new Date(val).getTime();
  110. },
  111. //时间戳转化为日期格式
  112. transTime(unixtime) {
  113. var dateTime = new Date(parseInt(unixtime));
  114. var year = dateTime.getFullYear();
  115. if (dateTime.getMonth() + 1 < 10) {
  116. var month = '0' + (dateTime.getMonth() + 1);
  117. } else {
  118. var month = dateTime.getMonth() + 1;
  119. }
  120. if (dateTime.getDate() < 10) {
  121. var day = '0' + dateTime.getDate();
  122. } else {
  123. var day = dateTime.getDate();
  124. }
  125. var now = new Date();
  126. var now_new = Date.parse(now.toDateString());
  127. var milliseconds = now_new - dateTime;
  128. var timeSpanStr = year + '-' + month + '-' + day;
  129. return timeSpanStr;
  130. },
  131. getReq(url, cb) {
  132. wx.request({
  133. url: url,
  134. method: 'get',
  135. header: {
  136. Accept: 'application/json',
  137. 'content-type': 'application/json;charset=UTF-8',
  138. token: wx.getStorageSync('token'),
  139. fSource: 1,
  140. },
  141. success: function (res) {
  142. if (res.data.status == 200) {
  143. return typeof cb == 'function' && cb(res.data);
  144. } else if (res.data.status == 600) {
  145. wx.showToast({
  146. title: res.data.message,
  147. icon: 'none',
  148. duration: 2000,
  149. mask: true,
  150. });
  151. setTimeout(() => {
  152. console.log(12312);
  153. wx.reLaunch({
  154. url: '/pages/login/login',
  155. });
  156. }, 2000);
  157. }
  158. },
  159. fail: (res) => {
  160. wx.hideLoading();
  161. this.networkAnomaly();
  162. return typeof cb == 'function' && cb(false);
  163. },
  164. });
  165. },
  166. getReqNew(url, data, cb) {
  167. wx.request({
  168. url: url,
  169. method: 'get',
  170. header: {
  171. Accept: 'application/json',
  172. 'content-type': 'application/json;charset=UTF-8',
  173. token: wx.getStorageSync('token'),
  174. fSource: 1,
  175. },
  176. data:data || {},
  177. success: function (res) {
  178. console.log(res)
  179. if (res.data.code == 0) {
  180. return typeof cb == 'function' && cb(res.data);
  181. } else if (res.data.code == 500) {
  182. wx.showToast({
  183. title: res.data.msg,
  184. icon: 'none',
  185. duration: 2000,
  186. mask: true,
  187. });
  188. }else if(res.statusCode == 404){
  189. wx.hideLoading();
  190. }
  191. },
  192. fail: (res) => {
  193. console.log(res)
  194. wx.hideLoading();
  195. this.networkAnomaly();
  196. return typeof cb == 'function' && cb(false);
  197. },
  198. });
  199. },
  200. postReq(url, data, cb) {
  201. wx.request({
  202. url: url,
  203. header: {
  204. Accept: 'application/json',
  205. 'content-type': 'application/json;charset=UTF-8',
  206. token: wx.getStorageSync('token'),
  207. fSource: 1,
  208. },
  209. data: {
  210. data,
  211. },
  212. method: 'post',
  213. success: function (res) {
  214. console.log(res)
  215. if (res.data.status == 200) {
  216. return typeof cb == 'function' && cb(res.data);
  217. } else if (res.status == 600) {
  218. wx.showToast({
  219. title: res.data.message || '网络错误',
  220. icon: 'none',
  221. duration: 2000,
  222. mask: true,
  223. });
  224. setTimeout(() => {
  225. wx.reLaunch({
  226. url: '/pages/login/login',
  227. });
  228. }, 2000);
  229. } else {
  230. wx.showToast({
  231. title: res.data.message || '网络错误',
  232. icon: 'none',
  233. duration: 2000,
  234. mask: true,
  235. });
  236. }
  237. },
  238. fail: () => {
  239. wx.hideLoading();
  240. this.networkAnomaly();
  241. return typeof cb == 'function' && cb(false);
  242. },
  243. });
  244. },
  245. postReqNew(url, data, cb) {
  246. wx.request({
  247. url: url,
  248. header: {
  249. Accept: 'application/json',
  250. 'content-type': 'application/json;charset=UTF-8',
  251. token: wx.getStorageSync('token'),
  252. fSource: 1,
  253. },
  254. data: data,
  255. method: 'post',
  256. success: function (res) {
  257. if (res.data.code == 0) {
  258. return typeof cb == 'function' && cb(res.data);
  259. } else if (res.status == 500) {
  260. wx.showToast({
  261. title: res.data.msg || '网络错误',
  262. icon: 'none',
  263. duration: 2000,
  264. mask: true,
  265. });
  266. // setTimeout(() => {
  267. // wx.reLaunch({
  268. // url: '/pages/login/login',
  269. // });
  270. // }, 2000);
  271. } else {
  272. wx.showToast({
  273. title: res.data.msg || '网络错误',
  274. icon: 'none',
  275. duration: 2000,
  276. mask: true,
  277. });
  278. }
  279. },
  280. fail: () => {
  281. wx.hideLoading();
  282. this.networkAnomaly();
  283. return typeof cb == 'function' && cb(false);
  284. },
  285. });
  286. },
  287. postReqNew2(url, data, cb) {
  288. wx.request({
  289. url: url,
  290. header: {
  291. Accept: 'application/json',
  292. 'content-type': 'application/json;charset=UTF-8',
  293. token: wx.getStorageSync('token'),
  294. fSource: 1,
  295. },
  296. data: data,
  297. method: 'post',
  298. success: function (res) {
  299. return typeof cb == 'function' && cb(res.data);
  300. },
  301. fail: () => {
  302. wx.hideLoading();
  303. this.networkAnomaly();
  304. return typeof cb == 'function' && cb(false);
  305. },
  306. });
  307. },
  308. // 获取字典封装方法
  309. getDictionaries(data, cb) {
  310. wx.request({
  311. url: this.globalData.httpsUrlServer + '/sysdictionaryvalue/selectDictionaryByFlag',
  312. header: {
  313. Accept: 'application/json',
  314. 'content-type': 'application/json;charset=UTF-8',
  315. token: wx.getStorageSync('token'),
  316. fSource: 1,
  317. },
  318. data: {
  319. data,
  320. },
  321. method: 'post',
  322. success: function (res) {
  323. // wx.hideLoading();
  324. return typeof cb == 'function' && cb(res.data);
  325. },
  326. fail: () => {
  327. // wx.hideLoading();
  328. // wx.showModal({
  329. // title: "网络错误",
  330. // content: "网络出错,请刷新重试",
  331. // showCancel: false,
  332. // })
  333. this.networkAnomaly();
  334. return typeof cb == 'function' && cb(false);
  335. },
  336. });
  337. },
  338. // 提示
  339. toast(title) {
  340. wx.showToast({
  341. title: title,
  342. icon: 'none',
  343. duration: 2000,
  344. });
  345. },
  346. // 等待
  347. loading(title = 'loading~') {
  348. wx.showLoading({
  349. title: title,
  350. mask: true,
  351. });
  352. },
  353. // 结束等待
  354. hideloading() {
  355. wx.hideLoading();
  356. },
  357. // 封装 验证手机号格式 方法
  358. checkPhone(phone) {
  359. if (!/^1\d{10}$/.test(phone)) {
  360. return false; //验证 失败
  361. } else {
  362. return true; //验证 成功
  363. }
  364. },
  365. // 封装 验证电话号 方法
  366. checkTel(tel) {
  367. if (!/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(tel)) {
  368. return false;
  369. } else {
  370. return true;
  371. }
  372. },
  373. // 封装 获取个人信息的 方法, 中心 或者 公园
  374. getUserTrue() {
  375. let url =
  376. this.globalData.httpsUrlServer + '/sysroleinfo/selectRoleInfoByUserId';
  377. const p = new Promise((resolve, reject) => {
  378. wx.request({
  379. url: url,
  380. method: 'get',
  381. header: {
  382. Accept: 'application/json',
  383. 'content-type': 'application/json;charset=UTF-8',
  384. token: wx.getStorageSync('token'),
  385. fSource: 1,
  386. },
  387. success: function (res) {
  388. resolve(res.data);
  389. },
  390. fail: function (err) {
  391. reject(err);
  392. },
  393. });
  394. });
  395. return p;
  396. },
  397. sendRequest(method, url, data) {
  398. url = this.globalData.httpsUrlServer + url;
  399. return new Promise((resolve, reject) => {
  400. wx.request({
  401. url,
  402. method,
  403. data,
  404. header: {
  405. Accept: 'application/json',
  406. 'content-type': 'application/json;charset=UTF-8',
  407. token: wx.getStorageSync('token'),
  408. fSource: 1,
  409. },
  410. success: function (res) {
  411. resolve(res.data);
  412. },
  413. fail: function (err) {
  414. reject(err);
  415. },
  416. });
  417. });
  418. },
  419. networkAnomaly() {
  420. if (!this.globalData.networkAnomalyFlag) {
  421. this.globalData.networkAnomalyFlag = setTimeout(() => {
  422. this.globalData.networkAnomalyFlag = null;
  423. }, 6000);
  424. wx.showModal({
  425. title: '网络错误',
  426. content: '网络出错,请刷新重试',
  427. showCancel: false,
  428. });
  429. }
  430. },
  431. });