app.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. //var bmap = require('/mapjs/bmap-wx.min.js');
  2. var QQMapWX = require("./utils/qqmap-wx-jssdk.js");
  3. var map;
  4. App({
  5. /**
  6. * 全局变量
  7. */
  8. // apiRoot: "https://qingyunhui.songlanyun.com/qyh/api/", // 正式环境api地址
  9. apiRoot: 'http://192.168.0.101:8687/qyh/api/',
  10. // apiRoot: 'http://192.168.0.70:8687/qyh/api/',
  11. // apiRoot: 'http://192.168.0.193:8687/qyh/api/',
  12. // apiRoot: 'http://192.168.0.232:8687/wjxy/api/', //黄理志
  13. // apiRoot: 'http://192.168.0.186:8687/wjxy/api/',
  14. // webViewUrl: "http://192.168.0.193:5173/#/", // 青创赛h5端地址
  15. webViewUrl: "https://saishi.songlanyun.com/h5/#/", // 青创赛h5端地址
  16. siteInfo: require("siteinfo.js"),
  17. token: "",
  18. // appAssetsUrl: 'https://pm.lanzhongrenli.com/qmjz/app', //静态资源服务器
  19. // appAssetsUrl: "https://wj.songlanyun.com/wjxy/statics/images/app", //静态资源服务器
  20. // appAssetsUrl2: 'http://192.168.0.101:8687/wjxy/statics/images/app/images/', //静态资源服务器
  21. // appAssetsUrl2: "https://wj.songlanyun.com/wjxy/statics/images/app/images/", //静态资源服务器
  22. appAssetsUrl: "https://qingyunhui.songlanyun.com/statics/images/app", //静态资源服务器
  23. appAssetsUrl2: "https://qingyunhui.songlanyun.com/statics/images/app/images/", //静态资源服务器
  24. appAssetsUrl3: "https://qingyunhui.songlanyun.com/statics/images/app/", //静态资源服务器
  25. //自定义参数
  26. params: {
  27. pePageToIndex: "",
  28. },
  29. bottomLeft: 0,
  30. sexList: [],
  31. /**
  32. * 生命周期函数--监听小程序初始化
  33. */
  34. onLaunch: function () {
  35. let that = this;
  36. map = new QQMapWX({
  37. key: "RA3BZ-PSGW4-GZUUX-DDAU7-6B54E-KJFQ7", // 必填
  38. });
  39. console.log("首次启动");
  40. const updateManager = wx.getUpdateManager();
  41. updateManager.onCheckForUpdate(function (res) {
  42. // 请求完新版本信息的回调
  43. console.log(res.hasUpdate);
  44. });
  45. updateManager.onUpdateReady(function () {
  46. wx.showModal({
  47. title: "更新提示",
  48. content: "新版本已经准备好,是否重启应用?",
  49. success (res) {
  50. if (res.confirm) {
  51. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  52. updateManager.applyUpdate();
  53. }
  54. },
  55. });
  56. });
  57. updateManager.onUpdateFailed(function () {
  58. // 新版本下载失败
  59. wx.showToast({
  60. title: "版本更新失败,请检查网络!",
  61. icon: "none",
  62. duration: 1500,
  63. });
  64. });
  65. /* setInterval(function(){
  66. wx.removeStorageSync('Weather');
  67. that.getWeaTher();
  68. console.log("天气已更新");
  69. },7200000);*/
  70. //that.getWeaTher();
  71. // http://zqgj.vaiwan.com
  72. // this.setApiRoot("http://zqgj.vaiwan.com/zqgj");
  73. /* wx.getNetworkType({
  74. success(res) {
  75. const networkType = res.networkType
  76. wx.showToast({
  77. title: '当前网络为' + networkType + '',
  78. icon: 'none'
  79. })
  80. }
  81. })*/
  82. //this.getLocal();
  83. //ios安全区域
  84. wx.getSystemInfo({
  85. success: (res) => {
  86. this.bottomLeft = res.screenHeight - res.safeArea.bottom;
  87. },
  88. });
  89. wx.request({
  90. url: this.apiRoot + "bizlibrary/infoList/gender",
  91. method: "get",
  92. success: function (res) {
  93. // console.log(res);
  94. if (res.data.code == 0) {
  95. that.sexList = res.data.dictList;
  96. }
  97. },
  98. });
  99. // that.font();
  100. },
  101. font () {
  102. wx.loadFontFace({
  103. family: "FZZhunYuan-M02S",
  104. global: true,
  105. source:
  106. 'url("https://wujiexiaoyuan-wechat.oss-cn-hangzhou.aliyuncs.com/font/FZZhunYuan-M02S.woff2")',
  107. // source: 'url("https://wujiexiaoyuan-wechat.oss-cn-hangzhou.aliyuncs.com/font/FZZhunYuan-M02S.ttf")',
  108. success: (msg) => {
  109. console.log(msg);
  110. },
  111. fail: (err) => {
  112. console.log(err);
  113. },
  114. complete: (res) => {
  115. // console.log(res);
  116. },
  117. });
  118. wx.loadFontFace({
  119. family: "FZCuYuan-M03",
  120. global: true,
  121. source:
  122. 'url("https://wujiexiaoyuan-wechat.oss-cn-hangzhou.aliyuncs.com/font/yuanGBK.woff2")',
  123. // source: 'url("https://wujiexiaoyuan-wechat.oss-cn-hangzhou.aliyuncs.com/font/yuanGBK.ttf")',
  124. success: (msg) => {
  125. console.log(msg);
  126. },
  127. fail: (err) => {
  128. console.log(err);
  129. },
  130. complete: (res) => {
  131. // console.log(res);
  132. },
  133. });
  134. },
  135. getLocal () {
  136. const _this = this;
  137. wx.getFuzzyLocation({
  138. type: "gcj02",
  139. success (res) {
  140. const latitude = res.latitude;
  141. const longitude = res.longitude;
  142. //通过【小程序定位】获取经纬度,在通过第三方sdk获取的地址信息
  143. _this.pointToAddress(latitude, longitude, function (address) {
  144. if (address) {
  145. wx.setStorageSync("CHOOSECITY", {
  146. cityName: address.city,
  147. areaName: address.district,
  148. });
  149. let pages = getCurrentPages();
  150. let prevpage = pages[pages.length - 1];
  151. if (prevpage.hasOwnProperty("loadCity")) {
  152. prevpage.loadCity();
  153. }
  154. }
  155. });
  156. },
  157. fail () {
  158. let pages = getCurrentPages();
  159. let prevpage = pages[pages.length - 1];
  160. if (prevpage.hasOwnProperty("loadCity")) {
  161. prevpage.loadCity();
  162. }
  163. },
  164. });
  165. },
  166. // 定义 pointToAddress 方法
  167. pointToAddress: function (latitude, longitude, callback) {
  168. var _this = this;
  169. // 调用接口
  170. map.reverseGeocoder({
  171. location: {
  172. latitude: latitude,
  173. longitude: longitude,
  174. },
  175. success: function (res) {
  176. // 解析成功返回地址
  177. callback(res.result.ad_info);
  178. },
  179. fail: function (res) {
  180. // console.log(res);
  181. },
  182. complete: function (res) { },
  183. });
  184. },
  185. /**
  186. * 当小程序启动,或从后台进入前台显示,会触发 onShow
  187. */
  188. /*
  189. onShow: function (options) {
  190. // 获取小程序基础信息
  191. this.getWxappBase(function (wxapp) {
  192. // 设置navbar标题、颜色
  193. wx.setNavigationBarColor({
  194. frontColor: wxapp.navbar.top_text_color.text,
  195. backgroundColor: wxapp.navbar.top_background_color
  196. })
  197. });
  198. },*/
  199. onShow: function (ops) {
  200. var that = this;
  201. wx.checkSession({
  202. success: function () {
  203. console.log("当前登录状态:有效");
  204. },
  205. fail: function () { },
  206. });
  207. wx.onNetworkStatusChange(function (res) {
  208. if (res.isConnected) {
  209. if (res.networkType !== "wifi") {
  210. wx.showToast({
  211. title: "注意!您正在使用" + res.networkType + "网络",
  212. icon: "none",
  213. });
  214. }
  215. }
  216. });
  217. },
  218. getWeaTher: function () {
  219. if (!wx.getStorageSync("Weather")) {
  220. // 新建百度地图对象
  221. var BMap = new bmap.BMapWX({
  222. ak: "pSzxYKshUcuo1Y9pPrbFs6r7LGvx8sxg",
  223. });
  224. var fail = function (data) {
  225. // console.log(data)
  226. };
  227. var success = function (data) {
  228. var weatherData = data.currentWeather[0];
  229. /* weatherData = '城市:' + weatherData.currentCity + '\n' + 'PM2.5:' + weatherData.pm25 + '\n' + '日期:' + weatherData.date + '\n' + '温度:' + weatherData.temperature + '\n' + '天气:' + weatherData.weatherDesc + '\n' + '风力:' + weatherData.wind + '\n';*/
  230. //Weather(weatherData.weatherDesc, _this, weatherData);
  231. wx.setStorageSync("Weather", weatherData);
  232. };
  233. // 发起weather请求
  234. BMap.weather({
  235. fail: fail,
  236. success: success,
  237. });
  238. }
  239. },
  240. /**
  241. * 设置api地址
  242. */
  243. setApiRoot: function () {
  244. //this.apiRoot = this.siteInfo.siteroot + '/api/';
  245. },
  246. /**
  247. * 获取小程序基础信息
  248. */
  249. /*
  250. getWxappBase: function (callback) {
  251. let App = this;
  252. App._get('wxapp/base', {}, function (result) {
  253. // 记录小程序基础信息
  254. wx.setStorageSync('wxapp', result.data.wxapp);
  255. callback && callback(result.data.wxapp);
  256. }, false, false);
  257. },*/
  258. /**
  259. * 显示成功提示框
  260. */
  261. showSuccess: function (msg, callback) {
  262. wx.showToast({
  263. title: msg,
  264. icon: "success",
  265. success: function () {
  266. callback &&
  267. setTimeout(function () {
  268. callback();
  269. }, 1500);
  270. },
  271. });
  272. },
  273. /**
  274. * 显示失败提示框
  275. */
  276. showError: function (msg, callback) {
  277. wx.showToast({
  278. title: msg,
  279. icon: "none",
  280. duration: 2000,
  281. success: function (res) {
  282. callback && callback();
  283. },
  284. });
  285. },
  286. /**
  287. * get请求
  288. */
  289. _get: function (url, data, success, fail, complete) {
  290. wx.showNavigationBarLoading();
  291. let App = this;
  292. // 构造请求参数
  293. data = data || {};
  294. wx.request({
  295. url: App.apiRoot + url,
  296. data: data,
  297. method: "get",
  298. success: function (res) {
  299. wx.hideNavigationBarLoading();
  300. wx.hideLoading();
  301. if (res.statusCode !== 200 || typeof res.data !== "object") {
  302. return false;
  303. }
  304. if (res.data.code === -1) {
  305. // 登录态失效, 重新登录
  306. return false;
  307. } else {
  308. success && success(res.data);
  309. }
  310. },
  311. fail: function (res) {
  312. wx.hideNavigationBarLoading();
  313. // console.log(res);
  314. App.showError(res.errMsg, function () {
  315. fail && fail(res);
  316. });
  317. },
  318. complete: function (res) {
  319. wx.hideNavigationBarLoading();
  320. complete && complete(res);
  321. },
  322. });
  323. },
  324. /**
  325. * post提交
  326. */
  327. _post_form: function (url, header, data, success, fail, complete) {
  328. wx.showNavigationBarLoading();
  329. let App = this;
  330. wx.request({
  331. url: App.apiRoot + url,
  332. header: {
  333. "content-type": header,
  334. },
  335. method: "POST",
  336. data: data,
  337. success: function (res) {
  338. wx.showNavigationBarLoading();
  339. wx.hideLoading();
  340. if (res.statusCode !== 200 && typeof res.data.code !== 1) {
  341. App.showError("网络请求出错");
  342. return false;
  343. }
  344. if (res.data.code === -1) {
  345. // 登录态失效, 重新登录
  346. App.doLogin(function () {
  347. App._post_form(url, data, success, fail);
  348. });
  349. return false;
  350. } else if (res.data.code === 0) {
  351. success && success(res.data);
  352. } else if (res.data.retCode === "000000") {
  353. success && success(res.data);
  354. return;
  355. } else {
  356. var msg = "";
  357. if (res.data.message) {
  358. msg = res.data.message;
  359. } else if (res.data.msg) {
  360. msg = res.data.msg;
  361. }
  362. App.showError(msg);
  363. success && success(res.data);
  364. return false;
  365. }
  366. },
  367. fail: function (res) {
  368. wx.showNavigationBarLoading();
  369. App.showError(res.errMsg, function () {
  370. fail && fail(res);
  371. });
  372. },
  373. complete: function (res) {
  374. complete && complete(res);
  375. wx.hideNavigationBarLoading();
  376. },
  377. });
  378. },
  379. // put 请求
  380. _put_form: function (url, header, data, success, fail, complete) {
  381. wx.showNavigationBarLoading();
  382. let App = this;
  383. wx.request({
  384. url: App.apiRoot + url,
  385. header: {
  386. "content-type": header,
  387. },
  388. method: "PUT",
  389. data: data,
  390. success: function (res) {
  391. wx.showNavigationBarLoading();
  392. wx.hideLoading();
  393. if (res.statusCode !== 200 && typeof res.data.code !== 1) {
  394. App.showError("网络请求出错");
  395. return false;
  396. }
  397. if (res.data.code === -1) {
  398. // 登录态失效, 重新登录
  399. App.doLogin(function () {
  400. App._post_form(url, data, success, fail);
  401. });
  402. return false;
  403. } else if (res.data.code === 0) {
  404. success && success(res.data);
  405. } else if (res.data.retCode === "000000") {
  406. success && success(res.data);
  407. return;
  408. } else {
  409. var msg = "";
  410. if (res.data.message) {
  411. msg = res.data.message;
  412. } else if (res.data.msg) {
  413. msg = res.data.msg;
  414. }
  415. // App.showError(msg);
  416. console.log(msg, 11111111);
  417. success && success(res.data);
  418. wx.showToast({
  419. title: msg,
  420. icon: "none",
  421. duration: 2000,
  422. });
  423. return false;
  424. }
  425. },
  426. fail: function (res) {
  427. wx.showNavigationBarLoading();
  428. App.showError(res.errMsg, function () {
  429. fail && fail(res);
  430. });
  431. },
  432. complete: function (res) {
  433. complete && complete(res);
  434. wx.hideNavigationBarLoading();
  435. },
  436. });
  437. },
  438. /**
  439. * 对象转URL
  440. */
  441. urlEncode: function urlencode (data) {
  442. var _result = [];
  443. for (var key in data) {
  444. var value = data[key];
  445. if (value.constructor == Array) {
  446. value.forEach(function (_value) {
  447. _result.push(key + "=" + _value);
  448. });
  449. } else {
  450. _result.push(key + "=" + value);
  451. }
  452. }
  453. return _result.join("&");
  454. },
  455. city: function () {
  456. return cityCode;
  457. },
  458. /**
  459. * 设置当前页面标题
  460. */
  461. /*
  462. setTitle: function() {
  463. let App = this,
  464. wxapp;
  465. if (wxapp = wx.getStorageSync('wxapp')) {
  466. wx.setNavigationBarTitle({
  467. title: wxapp.navbar.wxapp_title
  468. });
  469. } else {
  470. App.getWxappBase(function() {
  471. App.setTitle();
  472. });
  473. }
  474. },
  475. */
  476. });