|
|
@@ -4,141 +4,200 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { getToken } from '@/utils/auth'
|
|
|
-import { server_url } from '@/utils/config.js'
|
|
|
-var wv;
|
|
|
-export default {
|
|
|
- data() {
|
|
|
- return {
|
|
|
- src: '',
|
|
|
- query: {},
|
|
|
- webviewServer: server_url,
|
|
|
-
|
|
|
- };
|
|
|
- },
|
|
|
- onLoad(query) {
|
|
|
- this.query = query
|
|
|
-
|
|
|
- this.initData(query)
|
|
|
-
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- onReady() {
|
|
|
- // #ifdef APP-PLUS
|
|
|
- var self = this;
|
|
|
- var currentWebview = this.$scope.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
|
|
|
- setTimeout(function () {
|
|
|
- wv = currentWebview.children()[0];
|
|
|
- wv.addEventListener(
|
|
|
- "progressChanged",
|
|
|
- function (e) {
|
|
|
- wv.canBack(function (e) {
|
|
|
- self.canBack = e.canBack;
|
|
|
- });
|
|
|
- },
|
|
|
- false
|
|
|
- );
|
|
|
- }, 500); //如果是页面初始化调用时,需要延时一下
|
|
|
- // #endif
|
|
|
- },
|
|
|
- // 设备上点击返回按钮时的处理
|
|
|
- onBackPress(e) {
|
|
|
- if (wv && this.canBack) {
|
|
|
- wv.back();
|
|
|
- } else {
|
|
|
- // 没有可返回的页面了, 可以做些其他的处理, 比如回首页等等
|
|
|
- }
|
|
|
- return true;
|
|
|
- },
|
|
|
- /* onNavigationBarButtonTap(e) {
|
|
|
-
|
|
|
- // 返回
|
|
|
- if (e.index === 0) {
|
|
|
- // #ifdef H5
|
|
|
- uni.navigateBack();
|
|
|
- // #endif
|
|
|
-
|
|
|
- // #ifdef APP-PLUS
|
|
|
- if (this.canBack) {
|
|
|
- wv.back();
|
|
|
- } else {
|
|
|
- // 没有可返回的页面了, 可以做些其他的处理, 比如回首页等等
|
|
|
- }
|
|
|
- // #endif
|
|
|
- }
|
|
|
- // 首页
|
|
|
- if (e.index === 1) {
|
|
|
- // 显示tabbar
|
|
|
- //uni.showTabBar({
|
|
|
- // animation: false
|
|
|
- //});
|
|
|
- uni.switchTab({
|
|
|
- url: '/pages/index/index'
|
|
|
- });
|
|
|
- }
|
|
|
- }, */
|
|
|
- watch: {
|
|
|
- authtoken: {
|
|
|
- immediate: true,
|
|
|
- deep: true,
|
|
|
- handler(newVal) {
|
|
|
- // console.log(newVal,'newValnewValnewVal')
|
|
|
- // this.initData(this.query)
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- computed: {
|
|
|
- token() {
|
|
|
- return this.$store.state.user.token
|
|
|
- }
|
|
|
- },
|
|
|
- methods: {
|
|
|
+ import { sendPos } from "@/api/core/api";
|
|
|
+ import {
|
|
|
+ server_url
|
|
|
+ } from '@/utils/config.js'
|
|
|
+ var wv;
|
|
|
+ export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ timer: '',
|
|
|
+ src: '',
|
|
|
+ query: {},
|
|
|
+ webviewServer: server_url,
|
|
|
+ uuid: '',
|
|
|
+ };
|
|
|
+ },
|
|
|
+ onLoad(query) {
|
|
|
+ this.query = query
|
|
|
+
|
|
|
+ this.initData(query)
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- getUuid() {
|
|
|
- var uuid = "";
|
|
|
+ onReady() {
|
|
|
// #ifdef APP-PLUS
|
|
|
- if (plus.os.name == "Android") {
|
|
|
- try {
|
|
|
- var Build = plus.android.importClass("android.os.Build");
|
|
|
- var serial = Build.SERIAL;
|
|
|
- var mainActivity = plus.android.runtimeMainActivity();
|
|
|
- var Settings = plus.android.importClass("android.provider.Settings");
|
|
|
- var ANDROID_ID = Settings.Secure.getString(mainActivity.getContentResolver(), Settings.Secure.ANDROID_ID)
|
|
|
- uuid = `${ANDROID_ID}-${serial}`
|
|
|
- } catch (e) {
|
|
|
- console.log("获取设备唯一标识失败:", e);
|
|
|
- }
|
|
|
- }
|
|
|
+ var self = this;
|
|
|
+ var currentWebview = this.$scope
|
|
|
+ .$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
|
|
|
+ setTimeout(function() {
|
|
|
+ wv = currentWebview.children()[0];
|
|
|
+ wv.addEventListener(
|
|
|
+ "progressChanged",
|
|
|
+ function(e) {
|
|
|
+ wv.canBack(function(e) {
|
|
|
+ self.canBack = e.canBack;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ false
|
|
|
+ );
|
|
|
+ }, 500); //如果是页面初始化调用时,需要延时一下
|
|
|
// #endif
|
|
|
- return uuid;
|
|
|
},
|
|
|
-
|
|
|
-
|
|
|
- initData(query) {
|
|
|
-
|
|
|
+ // 设备上点击返回按钮时的处理
|
|
|
+ onBackPress(e) {
|
|
|
+ if (wv && this.canBack) {
|
|
|
+ wv.back();
|
|
|
+ } else {
|
|
|
+ // 没有可返回的页面了, 可以做些其他的处理, 比如回首页等等
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ /* onNavigationBarButtonTap(e) {
|
|
|
|
|
|
- let urlParams = ''
|
|
|
- for (let key in query) {
|
|
|
- if (key != 'token') {
|
|
|
- urlParams += `&${key}=${query[key]}`
|
|
|
+ // 返回
|
|
|
+ if (e.index === 0) {
|
|
|
+ // #ifdef H5
|
|
|
+ uni.navigateBack();
|
|
|
+ // #endif
|
|
|
+
|
|
|
+ // #ifdef APP-PLUS
|
|
|
+ if (this.canBack) {
|
|
|
+ wv.back();
|
|
|
+ } else {
|
|
|
+ // 没有可返回的页面了, 可以做些其他的处理, 比如回首页等等
|
|
|
+ }
|
|
|
+ // #endif
|
|
|
+ }
|
|
|
+ // 首页
|
|
|
+ if (e.index === 1) {
|
|
|
+ // 显示tabbar
|
|
|
+ //uni.showTabBar({
|
|
|
+ // animation: false
|
|
|
+ //});
|
|
|
+ uni.switchTab({
|
|
|
+ url: '/pages/index/index'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, */
|
|
|
+ watch: {
|
|
|
+ authtoken: {
|
|
|
+ immediate: true,
|
|
|
+ deep: true,
|
|
|
+ handler(newVal) {
|
|
|
+ // console.log(newVal,'newValnewValnewVal')
|
|
|
+ // this.initData(this.query)
|
|
|
}
|
|
|
}
|
|
|
- urlParams += `&uuid=${this.getUuid()}`
|
|
|
- urlParams = urlParams.replace('&', '')
|
|
|
- this.src = `${this.webviewServer}/mobile/pages/attachedVessel/index/?${urlParams}`
|
|
|
- console.log('webview地址', this.src)
|
|
|
},
|
|
|
- getLocation() {
|
|
|
-
|
|
|
+ computed: {
|
|
|
+ token() {
|
|
|
+ return this.$store.state.user.token
|
|
|
+ }
|
|
|
},
|
|
|
- scanCode() {
|
|
|
+ methods: {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ getUuid() {
|
|
|
+ var uuid = "";
|
|
|
+ // #ifdef APP-PLUS
|
|
|
+ if (plus.os.name == "Android") {
|
|
|
+ try {
|
|
|
+ var Build = plus.android.importClass("android.os.Build");
|
|
|
+ var serial = Build.SERIAL;
|
|
|
+ var mainActivity = plus.android.runtimeMainActivity();
|
|
|
+ var Settings = plus.android.importClass("android.provider.Settings");
|
|
|
+ var ANDROID_ID = Settings.Secure.getString(mainActivity.getContentResolver(), Settings.Secure
|
|
|
+ .ANDROID_ID)
|
|
|
+ uuid = `${ANDROID_ID}-${serial}`
|
|
|
+ } catch (e) {
|
|
|
+ console.log("获取设备唯一标识失败:", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // #endif
|
|
|
+ return uuid;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ initData(query) {
|
|
|
+
|
|
|
|
|
|
+ let urlParams = ''
|
|
|
+ for (let key in query) {
|
|
|
+ if (key != 'token') {
|
|
|
+ urlParams += `&${key}=${query[key]}`
|
|
|
+ }
|
|
|
+ }
|
|
|
+ urlParams += `&uuid=${this.getUuid()}`
|
|
|
+ urlParams = urlParams.replace('&', '')
|
|
|
+ this.src = `${this.webviewServer}/mobile/pages/attachedVessel/index/?${urlParams}`
|
|
|
+ console.log('webview地址', this.src)
|
|
|
+ this.uuid = this.getUuid()
|
|
|
+ //测试背景音频播放
|
|
|
+ // try {
|
|
|
+ // const bgAudioManager = uni.getBackgroundAudioManager();
|
|
|
+ // bgAudioManager.title = '致爱丽丝';
|
|
|
+ // bgAudioManager.singer = '暂无';
|
|
|
+ // bgAudioManager.coverImgUrl = 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/music-a.png';
|
|
|
+ // bgAudioManager.src = 'https://web-ext-storage.dcloud.net.cn/uni-app/ForElise.mp3';
|
|
|
+
|
|
|
+ // } catch (error) {
|
|
|
+ // //TODO handle the exception
|
|
|
+ // console.log('语音播报失败', error)
|
|
|
+ // }
|
|
|
+ try {
|
|
|
+ let this_ = this
|
|
|
+ this.timer = setInterval(() => {
|
|
|
+ uni.getLocation({
|
|
|
+ type: 'gcj02',
|
|
|
+ isHighAccuracy: true,
|
|
|
+ success: function(res) {
|
|
|
+ console.log('持续位置信息', res)
|
|
|
+ // console.log('当前位置的经度:' + res.longitude);
|
|
|
+ // console.log('当前位置的纬度:' + res.latitude);
|
|
|
+ let datas = {
|
|
|
+ deviceId:this_.uuid,
|
|
|
+ gpsTime:this_.dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
+ lat02:res.latitude,
|
|
|
+ lng02:res.longitude,
|
|
|
+ accuracy:res.accuracy,
|
|
|
+ speed:res.speed
|
|
|
+ }
|
|
|
+ console.log('上传定位信息',datas)
|
|
|
+ sendPos(datas).then(res => {
|
|
|
+ console.log('位置信息上传成功', res)
|
|
|
+ }).catch(err => {
|
|
|
+ console.log('位置信息上传失败', err)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }, 8 * 1000)
|
|
|
+ // uni.startLocationUpdate({
|
|
|
+ // type:'gcj02',
|
|
|
+ // // success: res => console.log('开启小程序接收位置消息成功'),
|
|
|
+ // fail: err => console.error('开启接收位置消息失败:', err),
|
|
|
+ // complete: msg => console.log('调用开启接收位置消息 API 完成')
|
|
|
+ // });
|
|
|
+
|
|
|
+ // uni.onLocationChange((res) => {
|
|
|
+ // console.log('持续位置信息', res)
|
|
|
+
|
|
|
+ // });
|
|
|
+ } catch (error) {
|
|
|
+ console.log('获取定位失败', error)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getLocation() {
|
|
|
+
|
|
|
+ },
|
|
|
+ scanCode() {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
</script>
|
|
|
|
|
|
-<style lang="scss"></style>
|
|
|
+<style lang="scss"></style>
|