App.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <script>
  2. import skJGPush from '@/libs/jgPush.js'
  3. import {openMessagePage} from '@/libs/tools.js'
  4. export default {
  5. globalData: {
  6. baseUrl: '',
  7. token: '',
  8. changeOrg:'',
  9. version: '', // 当前版本号
  10. buildType: 'pro', // 打包环境对应类型,pro 生产 uat 预发布 dev 本地开发
  11. envTips: '', // 环境文字提示
  12. theme: 'default', // 主题,default
  13. isIphoneXup: false //是否iphonex以及以上的版本
  14. },
  15. mounted() {
  16. // 非V3模式
  17. if (this.$scope) {
  18. this.$scope.globalData.token = this.$store.state.vuex_token;
  19. this.$scope.globalData.changeOrg = this.$store.state.vuex_changeOrg;
  20. } else {
  21. // V3模式
  22. getApp({ allowDefault: true }).globalData.token = this.$store.state.vuex_token;
  23. getApp({ allowDefault: true }).globalData.changeOrg = this.$store.state.vuex_changeOrg;
  24. }
  25. this.$config('init');
  26. },
  27. onLaunch: function() {
  28. console.log('App launch')
  29. this.$store.state.vuex_tempData = ''
  30. let bgAudioManager = uni.getBackgroundAudioManager();
  31. if(uni.getSystemInfoSync().platform == "ios"){
  32. // 请求定位权限
  33. let locationServicesEnabled = skJGPush.locationServicesEnabled()
  34. let locationAuthorizationStatus = skJGPush.getLocationAuthorizationStatus()
  35. console.log('locationAuthorizationStatus',locationAuthorizationStatus)
  36. if (locationServicesEnabled == true && locationAuthorizationStatus < 3) {
  37. skJGPush.requestLocationAuthorization((result)=>{
  38. console.log('定位权限',result.status)
  39. })
  40. }
  41. skJGPush.requestNotificationAuthorization((result)=>{
  42. let status = result.status
  43. console.log(result,'通知权限')
  44. if (status < 2) {
  45. uni.showModal({
  46. title: '提示',
  47. content: '您未打开通知权限,应用将无法收到消息通知,确定开启通知权限吗?',
  48. success: function (res) {
  49. if (res.confirm) {
  50. skJGPush.openSettingsForNotification()
  51. } else if (res.cancel) {
  52. console.log('用户点击取消');
  53. }
  54. }
  55. });
  56. }
  57. })
  58. }else{
  59. // 极光推送-init
  60. skJGPush.initJPushService()
  61. }
  62. // 极光推送-打开debug
  63. skJGPush.openDebug()
  64. skJGPush.initCrashHandler()
  65. // 极光推送-获取rid
  66. skJGPush.getRegistrationID(result => {
  67. console.log('【业务getRegistrationID】', result)
  68. })
  69. // 极光推送-通知事件回调
  70. skJGPush.addNotificationListener(result => {
  71. console.log('【业务addNotificationListener】', result)
  72. // 点击通知
  73. if(result.notificationEventType == 'notificationOpened'){
  74. this.setRead(result)
  75. }else if(result.notificationEventType == 'notificationArrived'){
  76. // 安卓铃声
  77. if(bgAudioManager&&uni.getSystemInfoSync().platform != "ios"){
  78. bgAudioManager.src = '/static/notes.mp3';
  79. bgAudioManager.play()
  80. }else{
  81. uni.vibrateLong({
  82. success: function () {
  83. console.log('vibrateLong success');
  84. }
  85. });
  86. }
  87. }else{
  88. // 清空角标
  89. skJGPush.setBadge(0)
  90. }
  91. })
  92. // 极光推送-标签别名事件回调
  93. skJGPush.addTagAliasListener(result => {
  94. console.log('【业务addTagAliasListener】', result)
  95. })
  96. // 连接状态
  97. skJGPush.addConnectEventListener(result => {
  98. console.log('【连接状态】', result)
  99. })
  100. },
  101. onShow: function() {
  102. console.log('App Show')
  103. },
  104. onHide: function() {
  105. console.log('App Hide')
  106. },
  107. methods:{
  108. setRead(item){
  109. const api = require("@/api/user.js")
  110. const token = getApp().globalData.token
  111. if(token){
  112. api.setReadNotice({'noticeId': item.extras.noticeId}).then(res => {
  113. console.log(res,'setRead')
  114. openMessagePage(item)
  115. })
  116. }else{
  117. uni.$emit("openMessage",item)
  118. }
  119. },
  120. }
  121. }
  122. </script>
  123. <style lang="scss">
  124. @import "./static/iconfont/iconfont.css";
  125. @import "uview-ui/index.scss";
  126. /*每个页面公共css */
  127. page {
  128. width: 100%;
  129. min-height: 100%;
  130. display: flex;
  131. background-color: #F8F8F8;
  132. }
  133. /* 登录页是否记住密码多选框样式 */
  134. uni-checkbox.login-form-checkbox .uni-checkbox-input{
  135. width: 24upx !important;
  136. height: 24upx !important;
  137. }
  138. .status_bar {
  139. height: var(--status-bar-height);
  140. width: 100%;
  141. }
  142. .isIPXup{
  143. padding-bottom: 64rpx !important;
  144. }
  145. /* form表单样式 */
  146. .form-box{
  147. background-color: #fff;
  148. padding: 0 30rpx;
  149. }
  150. .form-input {
  151. font-size: 28rpx;
  152. color: #333;
  153. text-align: right;
  154. width: 95%;
  155. box-sizing: border-box;
  156. height: 60rpx;
  157. line-height: 60rpx;
  158. &.textarea{
  159. height: 240rpx;
  160. padding: 24rpx 0;
  161. text-align: left;
  162. }
  163. }
  164. .form-input-placeholder {
  165. font-size: 28rpx;
  166. color: #999;
  167. }
  168. .form-textarea{
  169. height: 240rpx;
  170. padding: 24rpx 0;
  171. text-align: left;
  172. }
  173. .form-number-input{
  174. margin: 0 auto;
  175. }
  176. .u-required{
  177. position: relative;
  178. }
  179. .u-required:before{
  180. content: '*';
  181. position: absolute;
  182. left: -8px;
  183. top: 10upx;
  184. font-size: 14px;
  185. color: #fa3534;
  186. height: 9px;
  187. line-height: 1;
  188. }
  189. /* 元素宽度 百分比 */
  190. .uni-col-1{
  191. box-sizing: border-box;
  192. width: 10%;
  193. }
  194. .uni-col-2{
  195. box-sizing: border-box;
  196. width: 20%;
  197. }
  198. .uni-col-3{
  199. box-sizing: border-box;
  200. width: 30%;
  201. }
  202. .uni-col-4{
  203. box-sizing: border-box;
  204. width: 40%;
  205. }
  206. .uni-col-5{
  207. box-sizing: border-box;
  208. width: 50%;
  209. }
  210. .uni-col-6{
  211. box-sizing: border-box;
  212. width: 60%;
  213. }
  214. .uni-col-7{
  215. box-sizing: border-box;
  216. width: 70%;
  217. }
  218. .uni-col-8{
  219. box-sizing: border-box;
  220. width: 80%;
  221. }
  222. .uni-col-9{
  223. box-sizing: border-box;
  224. width: 90%;
  225. }
  226. .uni-col-10{
  227. box-sizing: border-box;
  228. width: 100%;
  229. }
  230. /* felx布局 */
  231. .flex{
  232. display: -webkit-flex; /* Chrome 21+, Safari 6.1+, iOS Safari 7+, Opera 15/16 */
  233. display: -moz-flex; /* Firefox 18+ */
  234. display: -ms-flexbox; /* IE 10 */
  235. display: flex; /* Chrome 29+, Firefox 22+, IE 11+, Opera 12.1/17/18, Android 4.4+ */
  236. }
  237. /*伸缩流方向*/
  238. .flex_column{
  239. -webkit-box-orient: vertical;
  240. -ms-flex-direction: column;
  241. -webkit-flex-direction: column;
  242. flex-direction: column;
  243. }
  244. /*主轴对齐*/
  245. .justify_center{
  246. -webkit-box-pack: center;
  247. -ms-flex-pack: center;
  248. -webkit-justify-content: center;
  249. justify-content: center;
  250. }
  251. .justify_end{
  252. -webkit-box-pack: end;
  253. -ms-flex-pack: end;
  254. -webkit-justify-content: flex-end;
  255. justify-content: flex-end;
  256. }
  257. .justify_between{
  258. -webkit-box-pack: justify;
  259. -ms-flex-pack: justify;
  260. -webkit-justify-content: space-between;
  261. justify-content: space-between;
  262. }
  263. /*侧轴对齐*/
  264. .align_start{
  265. -webkit-box-align: start;
  266. -ms-flex-align: start;
  267. -webkit-align-items: flex-start;
  268. align-items: flex-start;
  269. }
  270. .align_end{
  271. -webkit-box-align: end;
  272. -ms-flex-align: end;
  273. -webkit-align-items: flex-end;
  274. align-items: flex-end;
  275. }
  276. .align_center{
  277. -webkit-box-align: center;
  278. -ms-flex-align: center;
  279. -webkit-align-items: center;
  280. align-items: center;
  281. }
  282. .align_baseline{
  283. -webkit-box-align: baseline;
  284. -ms-flex-align: baseline;
  285. -webkit-align-items: baseline;
  286. align-items: baseline;
  287. }
  288. /*伸缩性*/
  289. .flex_auto{
  290. -webkit-box-flex: 1;
  291. -ms-flex: auto;
  292. -webkit-flex: auto;
  293. flex: auto;
  294. }
  295. .flex_1{
  296. -webkit-box-flex: 1;
  297. -ms-flex: 1;
  298. -webkit-flex: 1;
  299. flex: 1;
  300. }
  301. // ios15原生input的type=search时会默认自带搜索图标。
  302. // 在全局的公共样式隐藏ios自带搜索图标即可
  303. [type="search"]::-webkit-search-decoration {
  304. display: none;
  305. }
  306. uni-toast {
  307. z-index: 1000000;
  308. }
  309. </style>