zhaojs
2023-07-20 404ce868eec06566420c58c683dee54fc9ecff2a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<template>
    <view>
        <web-view v-if="webshow" :webview-styles="webviewStyles" :src="webviewUrl" @message='received'></web-view>
        <!-- taobao -->
        <u-popup v-model="empowerModel" mode="center" border-radius="12">
          <empowerModel @closemodel='closeMdl' @updataInfo='updataUser'></empowerModel>
        </u-popup>
    </view>
    
</template>
 
<script>
     import empowerModel from '../../components/empowerModel.vue'
    var wv;
    export default {
        components: {
          empowerModel
        },
        data() {
            return {
                webshow:true,
                empowerModel: false,
                webviewUrl: '',
                user:'',
                webviewStyles: {
                    progress: {
                        color: '#EE1B14'
                    }
                },
            }
        },
        onLoad(options) {
            if(!this.hasLogin){
                uni.reLaunch({
                    url:"/pages/login/wxlogin"
                })
            }
            else{
                const value = uni.getStorageSync('userInfo');
                console.log(value)
                this.webviewUrl = encodeURI('http://dfgapp.ushopvip.com/html/compareprice.html?token='+value.token);
                //this.webviewUrl = encodeURI('http://appapitest.ushopvip.com/html/compareprice.html?token='+value.token);
            }
            
        },
        onReady() {
          this.clearMuiBack();
        },
        methods: {
            
            received(e) {
                var res=e.detail.data[0];
                console.log(res);
                switch(res.action)
                {
                    case "back"://返回
                        this.backLast();
                        break;
                    case "tbauth"://淘宝授权
                        this.openTbMd();
                        break;
                    case "totb":
                        this.targetTb(res.tburl);
                        break;
                    case "copy":
                        this.getCopyTxt();
                        break;
                    case "getlike":
                        this.getLike();
                        break;
                }
            },
            getLike()
            {
                console.log('进来了');
                var postData={
                    deviceType: getApp().globalData.platform == 'android' ? (getApp().globalData.systemLevel < 10 ? 'IMEI' : 'OAID') :
                        'IDFA',
                    deviceValue: getApp().globalData.equipmentNumber
                };
                console.log(postData);
                var currentWebview = this.$scope.$getAppWebview().children()[0];
                currentWebview.evalJS(`likeDataGet(${JSON.stringify(postData)})`);
            },
            getCopyTxt()
            {
                uni.getClipboardData({
                    success: res => {
                      //调用页面里的方法
                      console.log(res, '======================================================');
                     var currentWebview = this.$scope.$getAppWebview().children()[0];
                      currentWebview.evalJS(`scanCode(${JSON.stringify(res)})`);
                    }
                  })
            },
            targetTb(tburl)
            {
                // #ifdef APP-PLUS
                if (plus.runtime.isApplicationExist({
                    pname: 'com.taobao.taobao',
                    action: 'taobao://'
                  })) {
                  const plug = uni.requireNativePlugin('xiguazhu-baichuan')
                  plug.detailPage({
                    url: tburl,
                    "openType": 0
                  }, result => {
                  });
                } else {
                  uni.navigateTo({
                      url:'@/webView/webView?url=' + tburl
                  })
                }
                // #endif
            },
            backLast()
            {
                console.log("返回")
                uni.navigateBack({
                    delta: 1
                });
            },
            closeMdl() {
              this.empowerModel = false;
              this.webshow=true;
            },
            openTbMd()
            {
                this.webshow=false;
                 this.empowerModel = true
            },
            updataUser() {
              var that = this;
              this.$u.api.getUserInfo({}).then(e => {
                utils.setCache('userInfo', e.data.userinfo)
                that.user = e.data.userinfo;
              }).catch(function(err) {})
            },
            // 关闭mui返回
              clearMuiBack() {
                // #ifdef APP-PLUS
             /*   var currentWebview = this.$scope.$getAppWebview().children()[0];
                //监听注入的js
                currentWebview.addEventListener("loaded", function() {
                  currentWebview.evalJS("mui.init({keyEventBind: {backbutton: false }});");
                }); */
                // #endif
              },
              
        },
        onNavigationBarButtonTap(e) {
            // #ifdef APP-PLUS
            const currentWebview = this.$scope.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
            var wv = currentWebview.children()[0]
            wv.reload();
            // #endif
        },
    }
</script>
 
<style>
 
</style>