app.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import {
  2. ApiModel
  3. } from './utils/api';
  4. App({
  5. onLaunch() {
  6. //自动登录
  7. if (wx.getStorageSync('userMsg').token && ![1007, 1008, 1155].includes(wx.getLaunchOptionsSync().scene)) this.globalData.http.basic({
  8. "classname": "webmanage.site.site",
  9. "method": "querySite_Parameter",
  10. "content": {}
  11. }).then(res => {
  12. console.log("验证登录", res)
  13. if (res.msg == '成功') {
  14. const loginMsg = require("./pages/login/modules/login");
  15. loginMsg.query_userauth();
  16. }
  17. })
  18. },
  19. initSocket() {
  20. let that = this;
  21. this.globalData.SocketTask = wx.connectSocket({
  22. // url: 'wss://meida.cnyunl.com/yos/webSocket/' + wx.getStorageSync('userMsg').token,
  23. url: 'ws://192.168.3.111:8100/yos/webSocket/' + wx.getStorageSync('userMsg').token,
  24. complete: (res) => {
  25. console.log(res)
  26. }
  27. })
  28. this.globalData.SocketTask.onOpen(function (res) {
  29. that.globalData.socketEstablish = true;
  30. })
  31. this.globalData.SocketTask.onMessage(function (res) {
  32. that.globalData.socket.callback(res)
  33. let data = JSON.parse(res.data);
  34. if (data.message.type == 'pay') {
  35. that.globalData.http.basic({
  36. "classname": "system.payorder.payorder",
  37. "method": "query_userauth",
  38. content: {
  39. nocache: true
  40. }
  41. }).then(res => {
  42. console.log('更新付费信息', res)
  43. wx.setStorageSync('userauth', res.data);
  44. wx.showToast({
  45. title: '应用付费信息已更新',
  46. icon: "none"
  47. })
  48. let page = getCurrentPages().find(v => v.__route__ == 'pages/tabbar/home/index')
  49. if (page) {
  50. page.refreshData();
  51. } else {
  52. that.globalData.refreshData();
  53. }
  54. });
  55. }
  56. })
  57. this.globalData.SocketTask.onError(function (res) {
  58. that.globalData.socketEstablish = false;
  59. })
  60. this.globalData.SocketTask.onClose(function (res) {
  61. that.globalData.socketEstablish = false;
  62. })
  63. },
  64. globalData: {
  65. http: new ApiModel(), //接口文件
  66. queryPer: require("./utils/queryPermissions"), //权限查询
  67. socketEstablish: false, //是否已经建立socket
  68. SocketTask: '', // Socket方法
  69. socket: { // Socket回调
  70. that: null, //保存this
  71. callback: function () {}
  72. },
  73. refreshData: null, //保存首页更新应用信息函数
  74. evidence: item => { //验证付费凭证,通过后跳转
  75. let userType = wx.getStorageSync('userMsg').usertype,
  76. isLeader = userType == 21;
  77. //应用是否开通,开通直接跳转
  78. if (item.isneedpay) return wx.showModal({
  79. title: '提示',
  80. content: `当前模块未付费,是否付费使用?`,
  81. confirmText: "前往付费",
  82. cancelText: isLeader ? "取消" : "提醒付费",
  83. complete: (res) => {
  84. if (res.confirm) {
  85. getApp().globalData.http.basic({
  86. "classname": "system.payorder.payorder",
  87. "method": "createOrder",
  88. "content": {},
  89. }).then(res => {
  90. console.log("新建订单", res)
  91. if (res.msg != '成功') return wx.showToast({
  92. title: res.msg,
  93. icon: "none",
  94. mask: true
  95. });
  96. wx.navigateTo({
  97. url: '/pages/teams/addOrder?sys_payorderid=' + res.data.sys_payorderid
  98. })
  99. })
  100. }
  101. if (res.cancel) {
  102. if (!isLeader) getApp().globalData.http.basic({
  103. "classname": "system.payorder.payorder",
  104. "method": "sendMessage",
  105. "content": {
  106. "sys_payorderid": ""
  107. }
  108. }).then(s => {
  109. wx.showToast({
  110. title: '已发送消息到主体主账号',
  111. icon: "none"
  112. })
  113. })
  114. }
  115. }
  116. })
  117. if (item.label == "营销物料") {
  118. wx.switchTab({
  119. url: item.path
  120. });
  121. } else {
  122. wx.navigateTo({
  123. url: item.path
  124. });
  125. }
  126. }
  127. },
  128. })