app.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import {
  2. ApiModel
  3. } from './utils/Api';
  4. import {
  5. evidence,
  6. update
  7. } from './utils/pay';
  8. App({
  9. onLaunch: function () {
  10. wx.getSystemInfo({
  11. success: e => {
  12. this.globalData.StatusBar = e.statusBarHeight;
  13. let custom = wx.getMenuButtonBoundingClientRect();
  14. this.globalData.Custom = custom;
  15. this.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
  16. }
  17. })
  18. },
  19. initSocket() {
  20. let that = this;
  21. this.globalData.SocketTask = wx.connectSocket({
  22. url: this.globalData.http.baseUrl.replace("https", "wss").replace("http", "ws") + '/yos/webSocket/' + wx.getStorageSync('userMsg').token,
  23. complete: (res) => {
  24. console.log(res)
  25. }
  26. })
  27. //获取领域对应账户
  28. /* this.globalData.http.basic({
  29. "classname": "sysmanage.develop.optiontype.optiontype",
  30. "method": "optiontypeselect",
  31. "content": {
  32. "pageNumber": 1,
  33. "pageSize": 9999,
  34. "typename": "domainrelatedaccounts"
  35. }
  36. }).then(res => {
  37. console.log("查询领域对应列表", res)
  38. wx.setStorageSync('domainrelatedaccounts', res.msg == '成功' ? res.data : [])
  39. }) */
  40. console.log(this.globalData.http.baseUrl.replace("https", "wss").replace("http", "ws") + '/yos/webSocket/' + wx.getStorageSync('userMsg').token)
  41. this.globalData.SocketTask.onOpen(function (res) {
  42. that.globalData.socketEstablish = true;
  43. })
  44. this.globalData.SocketTask.onMessage(function (res) {
  45. that.globalData.socket.callback(res)
  46. let data = JSON.parse(res.data);
  47. if (data.message.type == 'pay') update();
  48. })
  49. this.globalData.SocketTask.onError(function (res) {
  50. that.globalData.socketEstablish = false;
  51. })
  52. this.globalData.SocketTask.onClose(function (res) {
  53. that.globalData.socketEstablish = false;
  54. })
  55. },
  56. onShow() {
  57. const updateManager = wx.getUpdateManager()
  58. updateManager.onCheckForUpdate(function (res) {
  59. // 请求完新版本信息的回调
  60. console.log("是否有新版本", res.hasUpdate)
  61. })
  62. updateManager.onUpdateReady(function () {
  63. wx.showModal({
  64. title: '更新提示',
  65. content: '新版本已经准备好,是否重启应用?',
  66. showCancel: false,
  67. success: function (res) {
  68. if (res.confirm) {
  69. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  70. updateManager.applyUpdate()
  71. }
  72. }
  73. })
  74. })
  75. updateManager.onUpdateFailed(function () {
  76. // 新版本下载失败
  77. })
  78. },
  79. globalData: {
  80. http: new ApiModel, //挂载接口文件
  81. queryPer: require("./utils/queryPermissions"), //权限查询
  82. handleSelect: null, //处理选择结果函数
  83. collectCount: "", //购物车商品数量
  84. getCollectCount: null, // 获取购物车数量
  85. socketEstablish: false, //是否已经建立socket
  86. SocketTask: '', // Socket方法
  87. remindchangepassword_str: "",
  88. refreshData: null, //保存首页更新应用信息函数
  89. evidence
  90. },
  91. })