app.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. App({
  2. onLaunch: function (options) {
  3. if (options.query) {
  4. console.log('扫码加载', options.query)
  5. var code1 = decodeURIComponent(options.query.qrCode)
  6. var index = code1.lastIndexOf("\=");
  7. let code = code1.substring(index + 1, code1.length);
  8. this.globalData.scanCode = code
  9. console.log(code, 'ceode-------------------------------------')
  10. }
  11. if (my.canIUse('getUpdateManager')) {
  12. const updateManager = my.getUpdateManager()
  13. updateManager.onCheckForUpdate(function (res) {
  14. if (res.hasUpdate) {
  15. updateManager.onUpdateReady(function () {
  16. my.alert({
  17. title: '更新提示',
  18. content: '新版本已经准备好,是否重启应用?',
  19. success: function (res) {
  20. updateManager.applyUpdate()
  21. }
  22. })
  23. })
  24. updateManager.onUpdateFailed(function () {
  25. my.alert({
  26. title: '已经有新版本了哟~',
  27. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  28. })
  29. })
  30. }
  31. })
  32. } else {
  33. my.alert({
  34. title: '提示',
  35. content: '当前支付宝版本过低,无法使用该功能,请升级到最新支付宝版本后重试。'
  36. })
  37. }
  38. console.log(my.getStorageSync({
  39. 'key': 'token'
  40. }).data, 'XXXXXXXXXXXXXXXXXXXXX')
  41. },
  42. onShow(options){
  43. if (options.query) {
  44. console.log('扫码加载', options.query)
  45. var code1 = decodeURIComponent(options.query.qrCode)
  46. var index = code1.lastIndexOf("\=");
  47. let code = code1.substring(index + 1, code1.length);
  48. this.globalData.scanCode = code
  49. console.log(code, 'onShow-------------------------------------')
  50. }
  51. },
  52. globalData: {
  53. statusBarHeight: my.getSystemInfoSync()['statusBarHeight'],
  54. windowHeight: my.getSystemInfoSync()['windowHeight'],
  55. imgUrl: 'http://resource.bike.hanyiyun.com/',
  56. localSearchStop: true, //是否开启使用当前位置查询还车点
  57. screenHeight: '',
  58. login: false,
  59. scanCode: '', //扫描普通二维码跳转小程序解析出的车牌号码
  60. platform: '',
  61. version: '',
  62. req: true,
  63. id: 0,
  64. times: 60,
  65. invalid: false,
  66. // title: '禹见你', //全局修改此小程序名称
  67. // company:'禹州市途娱科技有限公司',
  68. // company_1:'途娱科技',
  69. // scanLength: 9,//车辆编码数
  70. // compatible: '',
  71. // title: '禹见你', //全局修改此小程序名称
  72. // logoUrl: '../../img/logo.png', //logo图片路径 网络图片/本地图片 dejin.png shanxianLg.png yuzhouLg.png dingding.png
  73. // appid: '2021002147603404', //小程序的appid wxc5f328a92356183f--遇见你appid
  74. // merchant_id: '1',
  75. // url: 'https://api.mtu.ximengnaikang.com/api', //线上域名
  76. // mapKey: 'GTLBZ-F6BKO-5EDWH-SDHIX-K2ART-O2FRQ' //地图key值
  77. appName: 'mtu',
  78. isUseTK: true, // 是否使用头盔
  79. isOnlineKefu: false, //是否使用在线客服
  80. title: '禹见你', //全局修改此小程序名称
  81. localSearchStop: false, //是否开启使用当前位置查询还车点
  82. isUseLinTing: true, //是否使用临时停车
  83. noShowRefOpenLock:false,//是否在两分钟后隐藏车辆为开锁按钮
  84. company: '禹州市途娱科技有限公司',
  85. company_1: '途娱科技',
  86. scanLength: 9, //车辆编码位数 跶跶出行为11位 沃骑、禹见你9位
  87. logoUrl: '../../img/logo.png', //禹见你
  88. appid: '2021002147603404', //禹见你
  89. url: 'https://api.mtu.ximengnaikang.com/api', //禹见你
  90. mapKey: 'GTLBZ-F6BKO-5EDWH-SDHIX-K2ART-O2FRQ', //禹见你
  91. merchant_id: 1, //商户id
  92. imgUrl: 'http://resource.mtu.ximengnaikang.com/',
  93. videoUrl: 'https://resource.mtu.ximengnaikang.com'
  94. // appName: 'tkcx',
  95. // isUseTK: true, // 是否使用头盔
  96. // localSearchStop: true, //是否开启使用当前位置查询还车点
  97. // isOnlineKefu: true, //是否使用在线客服
  98. // isUseLinTing: true, //是否使用临时停车
  99. // noShowRefOpenLock:false,//是否在两分钟后隐藏车辆为开锁按钮
  100. // title: '太康共享出行', //全局修改此小程序名称
  101. // company: '太康县速柯行科技有限公司',
  102. // company_1: '太康科技',
  103. // scanLength: 9, //车辆编码位数 跶跶出行为11位 沃骑、禹见你9位
  104. // logoUrl: '../../img/tkcx.png', //太康共享出行
  105. // appid: 'wxaaa1587f918c7e8a', //太康共享出行
  106. // url: 'https://api.yjtk.ximengnaikang.com/api', //太康共享出行
  107. // mapKey: 'GWTBZ-3B7HN-XYVFI-SNRHK-HF2F5-2WBB2', //太康共享出行
  108. // merchant_id: 1, //商户id
  109. // imgUrl: 'http://resource.mtu.ximengnaikang.com/',
  110. // videoUrl: 'https://resource.mtu.ximengnaikang.com'
  111. },
  112. request(api, params, method, req1) {
  113. var that = this;
  114. // if (req1 == false) return;
  115. // if (req1) {
  116. // that.globalData.req = false;
  117. // }
  118. // if (my.getStorageSync({ 'key': 'token' }).data != '' || my.getStorageSync({ 'key': 'token' }).data != undefined) {
  119. // if (req1 == true || req1 == undefined) {
  120. return new Promise((resolve, reject) => {
  121. my.request({
  122. url: this.globalData.url + api,
  123. data: params,
  124. headers: {
  125. 'content-type': 'application/json',
  126. 'Accept': 'application/json',
  127. 'Cache-Control': 'no-cache',
  128. 'Authorization': my.getStorageSync({
  129. 'key': 'token'
  130. }).data,
  131. 'merchant-id': this.globalData.merchant_id,
  132. 'source-type': 'alipay'
  133. },
  134. method: method,
  135. success: (res) => {
  136. // console.log(res)
  137. if (res.status == 450) {
  138. return;
  139. }
  140. if (res.status != 200) {
  141. let data = {
  142. response: res,
  143. 'url': api,
  144. 'data': params,
  145. 'merchant-id': this.globalData.merchant_id,
  146. 'authorization': my.getStorageSync({
  147. 'key': 'token'
  148. }).data,
  149. type: 'success',
  150. user: my.getStorageSync({
  151. 'key': 'userInfo'
  152. }).data ? my.getStorageSync({
  153. 'key': 'userInfo'
  154. }).data.user : '',
  155. version: '1.2.2'
  156. }
  157. my.request({
  158. url: this.globalData.url + '/logs', //仅为示例,并非真实的接口地址
  159. data: {
  160. data: data
  161. },
  162. method: 'POST',
  163. header: {
  164. 'content-type': 'application/json', // 默认值
  165. 'merchant-id': this.globalData.merchant_id
  166. },
  167. success(res) {
  168. console.log(res.data)
  169. }
  170. })
  171. }
  172. if (res.status != 200) {
  173. if (res.data.message == '订单不存在或订单已结算') {
  174. if (this.globalData.compatible) {
  175. my.reLaunch({
  176. url: '/pages/compatible/index/index',
  177. })
  178. } else {
  179. my.reLaunch({
  180. url: '/pages/index/index',
  181. })
  182. }
  183. return false;
  184. } else if (res.data.message == '运动中不能关锁') {
  185. return false;
  186. }
  187. if (res.message != undefined) {
  188. my.showToast({
  189. content: res.message,
  190. icon: 'none',
  191. duration: 3000,
  192. mask: true
  193. })
  194. } else if (res.data.message != undefined) {
  195. my.showToast({
  196. content: res.data.message,
  197. icon: 'none',
  198. duration: 3000,
  199. mask: true
  200. })
  201. }
  202. }
  203. console.log(res, 'token-------------------------------------------')
  204. resolve(res)
  205. },
  206. fail: (err) => {
  207. if (err.status == 401) {
  208. var timeout;
  209. console.log('token过期')
  210. my.removeStorageSync({
  211. key: 'token'
  212. })
  213. my.removeStorageSync({
  214. key: 'token_time'
  215. })
  216. // this.token()
  217. my.reLaunch({
  218. url: '/pages/index/index',
  219. })
  220. } else if (err.status == 404) {
  221. my.navigateTo({
  222. url: '/pages/undefind/undefind',
  223. })
  224. }
  225. else {
  226. my.showToast({
  227. content: err.data.message || err.data,
  228. icon: 'none',
  229. mask: true,
  230. duration: 3000,
  231. });
  232. }
  233. console.log(err, 'qingqiushibai')
  234. let data = {
  235. response: err,
  236. 'url': api,
  237. 'data': params,
  238. 'merchant-id': this.globalData.merchant_id,
  239. 'authorization': my.getStorageSync({
  240. 'key': 'token'
  241. }).data,
  242. type: 'success',
  243. user: my.getStorageSync({
  244. 'key': 'userInfo'
  245. }).data ? my.getStorageSync({
  246. 'key': 'userInfo'
  247. }).data.user : '',
  248. version: '1.2.2'
  249. }
  250. my.request({
  251. url: this.globalData.url + '/logs', //仅为示例,并非真实的接口地址
  252. data: {
  253. data: data
  254. },
  255. method: 'POST',
  256. header: {
  257. 'content-type': 'application/json', // 默认值
  258. 'merchant-id': this.globalData.merchant_id
  259. },
  260. success(res) {
  261. console.log(res.data)
  262. }
  263. })
  264. reject(err, "请求失败")
  265. },
  266. complete: () => {
  267. that.globalData.req = true
  268. }
  269. })
  270. })
  271. },
  272. login() {
  273. let that = this
  274. let token = my.getStorageSync({
  275. 'key': 'token'
  276. }).data
  277. let data = Math.round(new Date().getTime() / 1000).toString();
  278. let tokenTime = my.getStorageSync({
  279. 'key': 'token_time'
  280. }).data || 0;
  281. let cha = data - tokenTime
  282. let data1 = 60 * 60 * 4
  283. return new Promise((resolve, reject) => {
  284. if (token && cha < data1) {
  285. console.log(Math.round(new Date() / 1000), 'test--------')
  286. return resolve();
  287. } else {
  288. my.getAuthCode({
  289. success: (res) => {
  290. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  291. if (res.authCode) {
  292. console.log(res.authCode)
  293. var data = {
  294. 'code': res.authCode,
  295. // 'code':'040a788085094e47a75028874861PX410',
  296. 'appid': that.globalData.appid,
  297. 'type': 1
  298. };
  299. my.request({
  300. url: that.globalData.url + '/auth/weapp-login',
  301. data: data,
  302. headers: {
  303. 'content-type': 'application/json',
  304. 'Accept': 'application/json',
  305. 'Cache-Control': 'no-cache',
  306. // 'Authorization': my.getStorageSync({ 'key': 'token' }).data,
  307. 'merchant-id': that.globalData.merchant_id,
  308. 'source-type': 'alipay'
  309. },
  310. method: 'POST',
  311. success: (res) => {
  312. console.log(res, 'token')
  313. my.setStorageSync({
  314. 'key': 'token',
  315. data: res.data.token
  316. });
  317. my.setStorageSync({
  318. 'key': 'session_key',
  319. data: res.data.session_key
  320. });
  321. my.setStorageSync({
  322. 'key': 'token_time',
  323. data: res.data.exp
  324. });
  325. my.setStorageSync({
  326. 'key': 'user_ID',
  327. data: res.data.user.id
  328. });
  329. resolve()
  330. },
  331. fail: (err) => {
  332. console.log('err',err)
  333. if (err.status == 401) {
  334. my.showModal({
  335. title: '提示',
  336. content: '登录失效,是否重新登录',
  337. confirmText: '重新登录',
  338. complete: (res) => {
  339. if (res.confirm) {
  340. my.reLaunch({
  341. url: '/pages/index/index'
  342. })
  343. }
  344. }
  345. })
  346. return
  347. }
  348. if (err.status != 200) {
  349. console.log(res, 'cesgu---------------')
  350. my.showToast({
  351. content: err.data.message,
  352. icon: 'none'
  353. })
  354. return
  355. }
  356. my.alert({
  357. title: '提示',
  358. content: '可能网络不太好,请重试!',
  359. success: () => {
  360. my.reLaunch({
  361. url: '/pages/error/index?error=0'
  362. });
  363. }
  364. })
  365. }
  366. })
  367. } else {
  368. my.showToast({
  369. content: res.errMsg,
  370. icon: none,
  371. })
  372. }
  373. }
  374. })
  375. }
  376. })
  377. },
  378. })