main.stml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <safe-area class="page">
  3. <view class="body">
  4. <img id='loading' class="img" src="../../image/loading.gif" />
  5. </view>
  6. </safe-area>
  7. </template>
  8. <script>
  9. export default {
  10. name: 'main',
  11. apiready() {
  12. var that = this;
  13. api.openFrame({
  14. name: 'main',
  15. url: 'https://m.westkiss.com',
  16. rect: {
  17. x: 0,
  18. y: 0,
  19. w: 'auto',
  20. h: 'auto'
  21. },
  22. useWKWebView: true,
  23. historyGestureEnabled: true,
  24. bounces: false,
  25. progress:{
  26. type:'page'
  27. }
  28. });
  29. api.setStatusBarStyle({
  30. style: 'light'
  31. });
  32. api.setFrameClient({
  33. frameName:'main'
  34. },function(ret){
  35. that.onBrowserStateChange(ret);
  36. });
  37. this.removeLogic();
  38. api.addEventListener({
  39. name: 'keyback'
  40. }, function(ret, err){
  41. api.historyBack({
  42. frameName:'main'
  43. },function(ret,err){
  44. if(!ret.status){
  45. api.closeWidget();
  46. }
  47. });
  48. });
  49. this.removeLogic();
  50. this.googlePushInit();
  51. },
  52. data() {
  53. return {
  54. msg: "Hello APICloud",
  55. launchRemoved: false,
  56. loadingRemoved: false,
  57. };
  58. },
  59. methods: {
  60. onBrowserStateChange(ret){
  61. if(0 == ret.state){//开始加载
  62. if(!this.launchRemoved){
  63. this.launchRemoved = true;
  64. this.removeLaunch();
  65. }
  66. }
  67. if(2 == ret.state){
  68. if(!this.loadingRemoved){
  69. this.loadingRemoved = true;
  70. document.getElementById('loading').style.display = 'none';
  71. }
  72. }
  73. },
  74. removeLogic(){
  75. var that = this;
  76. setTimeout(function(){
  77. if(!that.launchRemoved){
  78. that.launchRemoved = true;
  79. that.removeLaunch();
  80. }
  81. }, 3000);
  82. },
  83. removeLaunch(){
  84. // 移除启动图
  85. api.removeLaunchView({
  86. animation:{
  87. type:"fade",
  88. subType:"from_right",
  89. duration:300
  90. }
  91. });
  92. },
  93. // google推送
  94. googlePushInit() {
  95. var googlePush = api.require('googlePush');
  96. // 初始化
  97. googlePush.initFcm(function(ret, err) {
  98. console.log('---initFcm satrt---');
  99. console.log(JSON.stringify(ret));
  100. console.log(JSON.stringify(err));
  101. console.log('---initFcm end---');
  102. // 获取token
  103. googlePush.registerToken(function(ret, err){
  104. console.log('---registerToken satrt---');
  105. console.log(JSON.stringify(ret));
  106. console.log(JSON.stringify(err));
  107. console.log('---registerToken end---');
  108. });
  109. // 收到消息时会触发
  110. googlePush.addOnMessageLisener(function(ret){
  111. console.log('---addOnMessageLisener satrt---');
  112. console.log(JSON.stringify(ret));
  113. console.log('---addOnMessageLisener end---');
  114. });
  115. });
  116. // 监听通知栏消息被点击
  117. api.addEventListener({
  118. name:'appintent'
  119. },function(ret,err){
  120. console.log('---appintent satrt---');
  121. /*
  122. {
  123. "iosUrl":"",
  124. "sourceAppId":"com.westkiss.m",
  125. "appParam":{
  126. "android.intent.extra.REFERRER":"com.westkiss.m",
  127. "google.delivered_priority":"high",
  128. "google.sent_time":1672015802071,
  129. "google.ttl":604800,
  130. "google.original_priority":"high",
  131. "title ":"02 test",
  132. "url":"https://m.westkiss.com/return_policy",
  133. "from":"506304076475",
  134. "google.message_id":"0:1672015802081797%3781dfb93781dfb9",
  135. "content":"this is test 002",
  136. "collapse_key":"com.westkiss.m"
  137. }
  138. }
  139. */
  140. console.log(JSON.stringify(ret));
  141. console.log(JSON.stringify(err));
  142. console.log('---appintent end---');
  143. var appParam = ret.appParam;
  144. if(api.systemType == 'ios'){
  145. var iosUrl = ret.iosUrl;
  146. } else {
  147. var sourceAppId = ret.sourceAppId;
  148. console.log(JSON.stringify(appParam));
  149. if(appParam.url) {
  150. api.openWin({
  151. name: 'WestKiss Sale',
  152. url: appParam.url,
  153. pageParam: {
  154. name: 'test'
  155. }
  156. });
  157. }
  158. }
  159. });
  160. }
  161. }
  162. };
  163. </script>
  164. <style>
  165. .page {
  166. width: 100%;
  167. height: 100%;
  168. background: #fff;
  169. display:flex;
  170. justify-content:center;
  171. align-items: center;
  172. }
  173. .body{
  174. position: relative;
  175. }
  176. .img{
  177. display:block;
  178. width: 40px;
  179. height: 40px;
  180. }
  181. </style>