123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <template>
- <view class="content">
- <view class="status_bar">
-
- </view>
- <web-view :src="url" :fullscreen='false' @message="messageData"></web-view>
- </view>
- </template>
- <script>
-
- var wv
- export default {
- data() {
- return {
- title: 'sanfan',
- url: 'http://175.178.26.5:20011/#/',
-
- src: "",
- wv: null,
- canBack: false,
- top: 0,
- height: 0,
- kbHeight: 0
- }
- },
- onBackPress() {
- if (wv && this.canBack) {
- wv.back();
- return true;
- }
- return false;
- },
- onReady() {
-
- var self = this;
- var currentWebview = this.$scope.$getAppWebview();
-
- setTimeout(function() {
- wv = currentWebview.children()[0];
- wv.addEventListener(
- "progressChanged",
- function(e) {
- wv.canBack(function(e) {
- self.canBack = e.canBack;
- });
- },
- false
- );
- }, 500);
-
- },
- onLoad() {
- uni.getSystemInfo({
-
- success: (sysinfo) => {
- this.height = sysinfo.windowHeight;
- },
- complete: () => {}
- });
- let info = uni.getSystemInfoSync();
- this.top = info.statusBarHeight;
- var currentWebview = this.$scope.$getAppWebview();
- setTimeout(() => {
- this.wv = currentWebview.children()[0];
- this.wv.setStyle({
- top: this.top,
-
- height: this.height - this.top,
- scalable: false,
- })
-
-
-
-
-
-
- }, 1000);
-
- uni.onKeyboardHeightChange((obj) => {
-
- let _sysInfo = uni.getSystemInfoSync();
- let _heightDiff = _sysInfo.screenHeight - _sysInfo.windowHeight
- let _diff = obj.height - _heightDiff
-
- this.kbHeight = (_diff > 0 ? _diff : 0) - 2;
- this.wv.setStyle({
- top: this.top,
-
- height: this.height - this.kbHeight,
-
- scalable: false,
- })
- })
-
- uni.onWindowResize(res => {
- if (res.size.windowHeight < this.height) {
- setTimeout(() => {
- this.wv.setStyle({
- top: this.top,
-
- height: this.height - this.kbHeight,
-
- scalable: false,
- })
- }, 50)
- } else {
- setTimeout(() => {
- this.wv.setStyle({
- top: this.top,
-
- height: this.height - this.top,
- bottom: 0
- })
- }, 50)
- }
- })
-
- uni.$on('connectStatusChange', (connectStatus) => {
- if (connectStatus) {
-
- jpushModule.getRegistrationID(result => {
- console.log(result, "注册ID.....")
- this.wv.evalJS(`getVueMessage(${JSON.stringify(result.registerID)})`);
- })
- }
- })
- },
- onUnload() {
-
- uni.$off('connectStatusChange')
- },
- methods: {
- messageData(e) {
- const data = e.detail.data
-
- if (data[0].type == 'file') {
- let url = data[0].url
- uni.downloadFile({
- url: url,
- success: function(res) {
-
- if (res.statusCode === 200) {
-
- uni.openDocument({
- filePath: res.tempFilePath,
- success: function(res) {},
- fail: function(error) {}
- });
- }
- },
- fail: function(error) {}
- });
-
- } else if (data[0].type == 'scanCode') {
-
- uni.scanCode({
- success: (res) => {
- this.wv.evalJS(
- `getVueMessage(${JSON.stringify(res.result)} , ${data[0].scanType})`);
- }
- });
- } else if (data[0].type == 'push') {
- uni.createPushMessage({
- title: "通知",
- content: data[0].content
- })
- } else if (data[0].type == 'message') {
- plus.runtime.setBadgeNumber(data[0].count)
- }
- }
- }
- }
- </script>
- <style>
- .content {}
- .status_bar {
- height: var(--status-bar-height);
- width: 100%;
- }
- </style>sss
|