App.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <script>
  2. // #ifdef APP-PLUS
  3. import APPUpdate, {
  4. getCurrentNo
  5. } from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
  6. import {
  7. callErrorCode
  8. } from "@/utils/commonDicts.js";
  9. import { KeepLive } from '@/uni_modules/android-keeplive'
  10. // #endif
  11. import {
  12. simpleDebounce
  13. } from "@/utils/util.js";
  14. export default {
  15. data() {
  16. return {
  17. g_wakelock: null,
  18. }
  19. },
  20. onLaunch: function() {
  21. //#ifdef APP-PLUS
  22. APPUpdate();
  23. getCurrentNo((data) => {
  24. this.$store.commit("app/SET_CURRENTVERSION", data.versionName);
  25. });
  26. plus.globalEvent.addEventListener('plusMessage', (msg) => {
  27. if (msg.data.args.data.name == 'postMessage') {
  28. const {
  29. type,
  30. data,
  31. action
  32. } = msg.data.args.data.arg;
  33. if (action === "message") {
  34. uni.$u.toast("e:" + data);
  35. } else if (action == "singInState") {
  36. this.$store.commit("app/SET_SIGNINSTATE", data)
  37. } else if (action == "registerInfo") {
  38. this.$store.commit("app/SET_REDIS_INFO", data)
  39. } else if (action == "disconnected") {
  40. // 重连不上 重新创建
  41. this.$store.dispatch("app/createWv");
  42. } else if (action === "phoneStatus") {
  43. this.$store.commit("app/SET_DIALING", data)
  44. } else if (action == "outbound") {
  45. data.action = "outbound";
  46. this.$store.dispatch("app/saveUnionAppCall", data)
  47. } else if (action == "incoming") {
  48. data.action = "incoming";
  49. // this.$store.commit("app/SET_ISREJECT", false);
  50. this.$store.dispatch("app/saveUnionAppCall", data).then(res => {
  51. uni.navigateTo({
  52. url: `/pages/callweb/callweb?phone=${data.phone}`
  53. })
  54. })
  55. }
  56. }
  57. });
  58. // this.addFlags();
  59. this.$store.dispatch("call/startPhoneListener");
  60. this.startKeepLive();
  61. // #endif
  62. },
  63. onShow: function() {
  64. this.$store.dispatch("app/register");
  65. },
  66. methods: {
  67. startKeepLive(){
  68. const keep =new KeepLive();
  69. keep.setTitle("时与APP");
  70. keep.setContent("后台运行中");
  71. // keep.setLargeIcon("icon");
  72. keep.setSmallIcon("icon"); //图标名字 图标放在 插件下面的 res/drawable 文件夹下
  73. keep.onAddBackgroundCallback(function(res){
  74. // console.log("后台运行 "+res)
  75. })
  76. keep.onAddScrrenListenerCallback(function(res){
  77. // console.log("屏幕开启状态 "+res)
  78. })
  79. keep.setWakeLock(1,"keeptag");// 设置唤醒类型
  80. keep.setAutoStartEnable(true)
  81. if(!keep.checkAppNotification()){
  82. keep.onOpenNotificationSetting(function(res){
  83. keep.register();
  84. var ignoring= keep.isIgnoringBatteryOptimizations();
  85. if(!ignoring){
  86. keep.requestIgnoreBatteryOptimizations();
  87. }
  88. })
  89. }else{
  90. keep.register();
  91. var ignoring= keep.isIgnoringBatteryOptimizations();
  92. if(!ignoring){
  93. keep.requestIgnoreBatteryOptimizations();
  94. }
  95. }
  96. },
  97. wakeLock() {
  98. //Android
  99. var main = plus.android.runtimeMainActivity();
  100. var Context = plus.android.importClass("android.content.Context");
  101. var PowerManager = plus.android.importClass("android.os.PowerManager");
  102. var pm = main.getSystemService(Context.POWER_SERVICE);
  103. this.g_wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ANY_NAME");
  104. this.g_wakelock.acquire();
  105. },
  106. // 禁止截屏
  107. addFlags() {
  108. // #ifdef APP-PLUS
  109. let osname = plus.os.name
  110. if (osname == "Android") {
  111. var activity = plus.android.runtimeMainActivity()
  112. plus.android.invoke(plus.android.invoke(activity, "getWindow"), "addFlags", 0x00002000)
  113. }
  114. // #endif
  115. },
  116. clearFlags() {
  117. // #ifdef APP-PLUS
  118. let osname = plus.os.name
  119. if (osname == "Android") {
  120. var activity = plus.android.runtimeMainActivity()
  121. plus.android.invoke(plus.android.invoke(activity, "getWindow"), "clearFlags", 0x00002000)
  122. }
  123. // #endif
  124. },
  125. },
  126. }
  127. </script>
  128. <style lang="scss">
  129. .card_wrap {
  130. margin: 0 20px;
  131. background-color: #fff;
  132. border-radius: 20rpx;
  133. overflow: hidden;
  134. margin-bottom: 20px;
  135. .header_wrap {
  136. display: flex;
  137. justify-content: space-between;
  138. padding: 10px;
  139. border-bottom: 1px solid #ddd;
  140. background-color: #fff;
  141. .header_left {
  142. font-size: 30rpx;
  143. }
  144. .haeder_right {
  145. display: flex;
  146. align-items: center;
  147. text {
  148. font-size: 28rpx;
  149. color: #b8b8b8;
  150. margin-right: 20rpx;
  151. }
  152. ::v-deep .u-icon__icon {
  153. font-size: 24rpx !important;
  154. }
  155. }
  156. }
  157. }
  158. /*#ifndef APP-NVUE*/
  159. .required {
  160. &::after {
  161. content: "*";
  162. color: red;
  163. margin-left: 6rpx;
  164. }
  165. }
  166. .form_required {
  167. position: relative;
  168. &::after {
  169. position: absolute;
  170. left: 12rpx;
  171. top: 50%;
  172. transform: translate(0%, -50%);
  173. content: "*";
  174. color: red;
  175. margin-left: 6rpx;
  176. }
  177. }
  178. /*#endif*/
  179. .u-cell__value {
  180. color: #999999 !important;
  181. }
  182. /*#ifndef APP-NVUE*/
  183. page {
  184. background-color: $uni-bg-color;
  185. }
  186. /*#endif*/
  187. .u-nav-slot {
  188. color: #108cff;
  189. }
  190. // 时间选择器不要高
  191. /*#ifndef APP-NVUE*/
  192. ::v-deep .uni-date__x-input {
  193. height: auto !important;
  194. font-size: 28rpx !important;
  195. }
  196. /*#endif*/
  197. .u-navbar__content__title {
  198. font-weight: bold;
  199. }
  200. @import "@/uni_modules/uview-ui/index.scss";
  201. /*每个页面公共css */
  202. </style>