App.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. /* 空路由拦截 */
  31. uni.addInterceptor("reLaunch", {
  32. invoke(e) {
  33. if (e.url == "/") {
  34. history.back();
  35. return false;
  36. }
  37. },
  38. });
  39. // #ifndef MP || H5
  40. /* 获取设备信息 */
  41. uni.getSystemInfo({
  42. success(res) {
  43. uni.setStorageSync('systemInfo', res.ua)
  44. }
  45. })
  46. const token = uni.getStorageSync("token");
  47. if (!token) return
  48. chat.initSocket()
  49. const userStore = useUserStore()
  50. userStore.getCurrentUser().then(res => {
  51. const {
  52. initLocale
  53. } = useLocale();
  54. initLocale()
  55. })
  56. this.handlePush()
  57. // this.getAppVersion()
  58. // 开启消息通知弹窗
  59. this.setPermissions()
  60. // #endif
  61. },
  62. methods: {
  63. handlePush() {
  64. // 获取unipushID
  65. uni.getPushClientId({
  66. success: (res) => {
  67. uni.setStorageSync('push_clientid', res.cid)
  68. },
  69. fail(err) {}
  70. })
  71. // 处理推送消息
  72. uni.onPushMessage(res => {
  73. const data = res.data.payload.data
  74. // 公告跟系统消息
  75. if (data.messageType == 1 || data.messageType == 3) {
  76. uni.navigateTo({
  77. url: '/pages/message/messageDetail/index?id=' + data.id
  78. });
  79. return
  80. }
  81. // 流程消息(包括委托)
  82. if (data.messageType == 2) {
  83. return this.toFlow(data.id)
  84. }
  85. // 日程消息
  86. if (data.messageType == 4) {
  87. return this.toSchedule(data.id)
  88. }
  89. // 聊天
  90. if (data.messageType == 100) {
  91. return this.toIm(res.data.payload)
  92. }
  93. })
  94. },
  95. setPermissions() {
  96. if (plus.os.name == 'Android') { // 判断是Android
  97. var main = plus.android.runtimeMainActivity();
  98. var pkName = main.getPackageName();
  99. var uid = main.getApplicationInfo().plusGetAttribute("uid");
  100. var NotificationManagerCompat = plus.android.importClass(
  101. "android.support.v4.app.NotificationManagerCompat");
  102. //android.support.v4升级为androidx
  103. if (NotificationManagerCompat == null) {
  104. NotificationManagerCompat = plus.android.importClass(
  105. "androidx.core.app.NotificationManagerCompat");
  106. }
  107. var areNotificationsEnabled = NotificationManagerCompat.from(main).areNotificationsEnabled();
  108. // 未开通‘允许通知’权限,则弹窗提醒开通,并点击确认后,跳转到系统设置页面进行设置
  109. if (!areNotificationsEnabled) {
  110. uni.showModal({
  111. title: '通知权限开启提醒',
  112. content: '您还没有开启通知权限,无法接受到消息通知,请前往设置!',
  113. showCancel: false,
  114. confirmText: '去设置',
  115. success: function(res) {
  116. if (res.confirm) {
  117. var Intent = plus.android.importClass('android.content.Intent');
  118. var Build = plus.android.importClass("android.os.Build");
  119. //android 8.0引导
  120. if (Build.VERSION.SDK_INT >= 26) {
  121. var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
  122. intent.putExtra('android.provider.extra.APP_PACKAGE', pkName);
  123. } else if (Build.VERSION.SDK_INT >= 21) { //android 5.0-7.0
  124. var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
  125. intent.putExtra("app_package", pkName);
  126. intent.putExtra("app_uid", uid);
  127. } else { //(<21)其他--跳转到该应用管理的详情页
  128. intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
  129. var uri = Uri.fromParts("package", mainActivity.getPackageName(),
  130. null);
  131. intent.setData(uri);
  132. }
  133. // 跳转到该应用的系统通知设置页
  134. main.startActivity(intent);
  135. }
  136. }
  137. });
  138. }
  139. } else if (plus.os.name == 'iOS') { // 判断是ISO
  140. var isOn = undefined;
  141. var types = 0;
  142. var app = plus.ios.invoke('UIApplication', 'sharedApplication');
  143. var settings = plus.ios.invoke(app, 'currentUserNotificationSettings');
  144. if (settings) {
  145. types = settings.plusGetAttribute('types');
  146. plus.ios.deleteObject(settings);
  147. } else {
  148. types = plus.ios.invoke(app, 'enabledRemoteNotificationTypes');
  149. }
  150. plus.ios.deleteObject(app);
  151. isOn = (0 != types);
  152. if (isOn == false) {
  153. uni.showModal({
  154. title: '通知权限开启提醒',
  155. content: '您还没有开启通知权限,无法接受到消息通知,请前往设置!',
  156. showCancel: false,
  157. confirmText: '去设置',
  158. success: function(res) {
  159. if (res.confirm) {
  160. var app = plus.ios.invoke('UIApplication', 'sharedApplication');
  161. var setting = plus.ios.invoke('NSURL', 'URLWithString:', 'app-settings:');
  162. plus.ios.invoke(app, 'openURL:', setting);
  163. plus.ios.deleteObject(setting);
  164. plus.ios.deleteObject(app);
  165. }
  166. }
  167. });
  168. }
  169. }
  170. },
  171. getAppVersion() {
  172. getAppVersion().then(res => {
  173. let data = res.data.sysVersion || ''
  174. const matches = data.match(/(\d+\.\d+\.\d+)/);
  175. if (matches && matches.length > 0) this.Apk =
  176. `https://cdn.jnpfsoft.com/apk/Android-java-${matches[0]}.apk`
  177. data.trim();
  178. this.version = Number(data.replace(/[^0-9]/ig, ""))
  179. this.$nextTick(() => {
  180. this.onUpdate()
  181. })
  182. }).catch((err) => {})
  183. },
  184. onUpdate() {
  185. plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
  186. let resVersion = this.define.sysVersion;
  187. resVersion.trim();
  188. this.resVersion = Number(resVersion.replace(/[^0-9]/ig, ""))
  189. if (this.version != this.resVersion) {
  190. process.env.NODE_ENV === "production" ?
  191. uni.setStorageSync('isUpdate', 1) : uni.removeStorageSync('isUpdate')
  192. uni.showModal({ //提醒用户更新
  193. title: "立即更新版本",
  194. success: (res) => {
  195. if (res.confirm) {
  196. uni.removeStorageSync('isUpdate')
  197. let system = plus.os.name;
  198. if (system === 'Android') {
  199. // let url = devLanguage ? javaApk : dotNetApk;
  200. if (!this.Apk) return this.$u.toast('下载链接为空')
  201. plus.runtime.openURL(this.Apk)
  202. // uni.downloadFile({
  203. // //下载地址
  204. // url: url,
  205. // success: data => {
  206. // if (data.statusCode === 200) {
  207. // plus.runtime.install(data
  208. // .tempFilePath, {
  209. // force: false
  210. // },
  211. // function() {
  212. // plus.runtime
  213. // .restart();
  214. // });
  215. // }
  216. // }
  217. // })
  218. } else {
  219. plus.runtime.launchApplication({
  220. action: `itms-apps://itunes.apple.com/cn/app/id${'appleId自行配置'}`
  221. }, function(e) {});
  222. }
  223. } else if (res.cancel) {
  224. if (this.modileSystem == 'ios') {
  225. plus.ios.import("UIApplication")
  226. .sharedApplication()
  227. .performSelector("exit")
  228. } else if (this.modileSystem == 'android') {
  229. plus.runtime.quit();
  230. }
  231. }
  232. }
  233. })
  234. }
  235. })
  236. },
  237. // 打开聊天页面
  238. toIm(item) {
  239. chatStore.reduceBadgeNum(0)
  240. uni.navigateTo({
  241. url: '/pages/message/im/index?name=' + item.realName + '/' + item.account + '&formUserId=' +
  242. item.formUserId +
  243. '&headIcon=' +
  244. item
  245. .headIcon
  246. })
  247. },
  248. // 打开日程页面
  249. toSchedule(id) {
  250. getMessageDetail(id).then(res => {
  251. chatStore.setMsgInfoNum()
  252. let bodyText = res.data.bodyText ? JSON.parse(res.data.bodyText) : {};
  253. if (bodyText.type == 3) return
  254. let groupId = bodyText.groupId || ''
  255. uni.navigateTo({
  256. url: '/pages/workFlow/schedule/detail?groupId=' + groupId +
  257. '&id=' + bodyText.id
  258. });
  259. })
  260. },
  261. // 打开流程页面
  262. toFlow(id) {
  263. getMessageDetail(id).then(res => {
  264. chatStore.setMsgInfoNum()
  265. let bodyText = res.data.bodyText ? JSON.parse(res.data.bodyText) : {};
  266. if (res.data.flowType == 2) {
  267. let url = '/pages/workFlow/entrustAgent/index'
  268. url = bodyText.type == 1 ? url + '?index=1' : url + '?index=2'
  269. uni.navigateTo({
  270. url: url
  271. });
  272. return
  273. }
  274. let config = {
  275. fullName: res.data.title,
  276. id: bodyText.operatorId || res.data.id,
  277. ...bodyText
  278. }
  279. checkInfo(bodyText.operatorId || config.taskId, config.opType).then(res => {
  280. config.opType = res.data.opType;
  281. setTimeout(() => {
  282. uni.navigateTo({
  283. url: '/pages/workFlow/flowBefore/index?config=' +
  284. this.jnpf.base64.encode(JSON.stringify(config))
  285. });
  286. }, 300)
  287. })
  288. })
  289. }
  290. }
  291. }
  292. </script>
  293. <style lang="scss">
  294. /*每个页面公共css */
  295. @import "@/uni_modules/vk-uview-ui/index.scss";
  296. @import "@/assets/iconfont/ym/iconfont.css";
  297. @import "@/assets/iconfont/custom/iconfont.css";
  298. @import "@/assets/scss/common.scss";
  299. @import "@/assets/scss/components.scss";
  300. </style>