App.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <script>
  2. import chat from '@/libs/chat.js'
  3. import {
  4. getAppVersion
  5. } from '@/api/common.js'
  6. import {
  7. getMessageDetail,
  8. checkInfo,
  9. } from '@/api/message.js'
  10. import {
  11. useLocale
  12. } from '@/locale/useLocale';
  13. import {
  14. useChatStore
  15. } from '@/store/modules/chat'
  16. import {
  17. useUserStore
  18. } from '@/store/modules/user'
  19. const chatStore = useChatStore()
  20. export default {
  21. data() {
  22. return {
  23. version: 0,
  24. resVersion: 0,
  25. modileSystem: 'android',
  26. Apk: ''
  27. }
  28. },
  29. onLaunch() {
  30. // #ifndef APP-HARMONY || MP || H5
  31. /* uniPush */
  32. // uni.getPushClientId({
  33. // success: (res) => {
  34. // userStore.setCid(res.cid)
  35. // this.handlePush()
  36. // },
  37. // fail(err) {}
  38. // })
  39. /* H5+ */
  40. /* 获取设备信息 */
  41. uni.getSystemInfo({
  42. success(res) {
  43. uni.setStorageSync('systemInfo', res.ua)
  44. }
  45. })
  46. this.handlePush()
  47. // this.getAppVersion()
  48. // #endif
  49. const token = uni.getStorageSync("token");
  50. if (!token) return
  51. chat.initSocket()
  52. const userStore = useUserStore()
  53. userStore.getCurrentUser().then(res => {
  54. const {
  55. initLocale
  56. } = useLocale();
  57. initLocale()
  58. })
  59. },
  60. methods: {
  61. getAppVersion() {
  62. getAppVersion().then(res => {
  63. let data = res.data.sysVersion || ''
  64. const matches = data.match(/(\d+\.\d+\.\d+)/);
  65. if (matches && matches.length > 0) this.Apk =
  66. `https://cdn.jnpfsoft.com/apk/Android-java-${matches[0]}.apk`
  67. data.trim();
  68. this.version = Number(data.replace(/[^0-9]/ig, ""))
  69. this.$nextTick(() => {
  70. this.onUpdate()
  71. })
  72. }).catch((err) => {})
  73. },
  74. onUpdate() {
  75. plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
  76. let resVersion = this.define.sysVersion;
  77. resVersion.trim();
  78. this.resVersion = Number(resVersion.replace(/[^0-9]/ig, ""))
  79. if (this.version != this.resVersion) {
  80. process.env.NODE_ENV === "production" ?
  81. uni.setStorageSync('isUpdate', 1) : uni.removeStorageSync('isUpdate')
  82. uni.showModal({ //提醒用户更新
  83. title: "立即更新版本",
  84. success: (res) => {
  85. if (res.confirm) {
  86. uni.removeStorageSync('isUpdate')
  87. let system = plus.os.name;
  88. if (system === 'Android') {
  89. // let url = devLanguage ? javaApk : dotNetApk;
  90. if (!this.Apk) return this.$u.toast('下载链接为空')
  91. plus.runtime.openURL(this.Apk)
  92. // uni.downloadFile({
  93. // //下载地址
  94. // url: url,
  95. // success: data => {
  96. // if (data.statusCode === 200) {
  97. // plus.runtime.install(data
  98. // .tempFilePath, {
  99. // force: false
  100. // },
  101. // function() {
  102. // plus.runtime
  103. // .restart();
  104. // });
  105. // }
  106. // }
  107. // })
  108. } else {
  109. plus.runtime.launchApplication({
  110. action: `itms-apps://itunes.apple.com/cn/app/id${'appleId自行配置'}`
  111. }, function(e) {});
  112. }
  113. } else if (res.cancel) {
  114. if (this.modileSystem == 'ios') {
  115. plus.ios.import("UIApplication")
  116. .sharedApplication()
  117. .performSelector("exit")
  118. } else if (this.modileSystem == 'android') {
  119. plus.runtime.quit();
  120. }
  121. }
  122. }
  123. })
  124. }
  125. })
  126. },
  127. // 打开聊天页面
  128. toIm(item) {
  129. chatStore.reduceBadgeNum(0)
  130. uni.navigateTo({
  131. url: '/pages/message/im/index?name=' + item.realName + '/' + item.account + '&formUserId=' +
  132. item.formUserId +
  133. '&headIcon=' +
  134. item
  135. .headIcon
  136. })
  137. },
  138. // 打开日程页面
  139. toSchedule(id) {
  140. getMessageDetail(id).then(res => {
  141. chatStore.setMsgInfoNum()
  142. let bodyText = res.data.bodyText ? JSON.parse(res.data.bodyText) : {};
  143. if (bodyText.type == 3) return
  144. let groupId = bodyText.groupId || ''
  145. uni.navigateTo({
  146. url: '/pages/workFlow/schedule/detail?groupId=' + groupId +
  147. '&id=' + bodyText.id
  148. });
  149. })
  150. },
  151. // 打开流程页面
  152. toFlow(id) {
  153. getMessageDetail(id).then(res => {
  154. chatStore.setMsgInfoNum()
  155. let bodyText = res.data.bodyText ? JSON.parse(res.data.bodyText) : {};
  156. if (res.data.flowType == 2) {
  157. let url = '/pages/my/entrustAgent/index'
  158. url = bodyText.type == 1 ? url + '?index=1' : url + '?index=2'
  159. uni.navigateTo({
  160. url: url
  161. });
  162. return
  163. }
  164. let config = {
  165. fullName: res.data.title,
  166. id: bodyText.operatorId,
  167. ...bodyText
  168. }
  169. checkInfo(bodyText.operatorId || config.taskId, config.opType).then(res => {
  170. config.opType = res.data.opType;
  171. setTimeout(() => {
  172. uni.navigateTo({
  173. url: '/pages/workFlow/flowBefore/index?config=' +
  174. this.jnpf.base64.encode(JSON.stringify(config))
  175. });
  176. }, 300)
  177. })
  178. })
  179. },
  180. // 处理推送消息
  181. handlePush() {
  182. // #ifndef APP-HARMONY || MP || H5
  183. /* H5+ */
  184. plus.push.addEventListener(
  185. 'click',
  186. msg => {
  187. const messageType = msg.payload.messageType
  188. // 公告跟系统消息
  189. if (messageType == 1 || messageType == 3) {
  190. uni.navigateTo({
  191. url: '/pages/message/messageDetail/index?id=' + msg.payload.id
  192. });
  193. return
  194. }
  195. // 流程消息(包括委托)
  196. if (messageType == 2) {
  197. return this.toFlow(msg.payload.id)
  198. }
  199. // 日程消息
  200. if (messageType == 4) {
  201. return this.toSchedule(msg.payload.id)
  202. }
  203. // 聊天
  204. if (messageType == 100) {
  205. return this.toIm(msg.payload)
  206. }
  207. })
  208. /* uniPush */
  209. // uni.onPushMessage((res) => {
  210. // // const pages = getCurrentPages();
  211. // // const currentRoute = pages[pages.length - 1].$page.fullPath
  212. // let payload = res.data.payload
  213. // let text = JSON.parse(this.jnpf.base64.decode(payload.text))
  214. // let content = text.type == 1 ? '公告' : text.type == 2 ? '流程' : '聊天'
  215. // let title = text.type == 3 ? text.name : text.title
  216. // if (res.type === 'receive') {
  217. // uni.createPushMessage({
  218. // title,
  219. // content: `你有一条${content}消息`,
  220. // payload,
  221. // icon: './static/logo.png',
  222. // success: (res) => {},
  223. // fail: (err) => {}
  224. // })
  225. // } else {
  226. // if (text.type == 1) {
  227. // uni.navigateTo({
  228. // url: '/pages/message/messageDetail/index?id=' + text.id
  229. // });
  230. // } else if (text.type == 2) {
  231. // this.toFlow(text)
  232. // } else {
  233. // this.toIm(text)
  234. // }
  235. // }
  236. // })
  237. // #endif
  238. },
  239. }
  240. }
  241. </script>
  242. <style lang="scss">
  243. /*每个页面公共css */
  244. @import "@/uni_modules/vk-uview-ui/index.scss";
  245. @import "@/assets/iconfont/ym/iconfont.css";
  246. @import "@/assets/iconfont/custom/iconfont.css";
  247. @import "@/assets/scss/common.scss";
  248. @import "@/assets/scss/components.scss";
  249. </style>