Browse Source

更改wordpress 配置字段后,修改前端逻辑

chenlei1231 4 months ago
parent
commit
3ec4e2e332
1 changed files with 62 additions and 67 deletions
  1. 62 67
      src/hooks/component/useIframe.js

+ 62 - 67
src/hooks/component/useIframe.js

@@ -1,4 +1,4 @@
-import { postAction } from '/@/api/manage/manage'
+import { postAction } from '/@/api/manage/manage';
 import { inject } from 'vue';
 
 // TODO 先兼容vue2代码迁移,后期替换为vue3的写法, 当前from src/mixins/iframeMixin.js
@@ -12,102 +12,97 @@ export const useIframe = {
       pageError: false,
       wpConfig: {},
       wordpressSetting: '',
-      openSetting: []
-    }
+      openSetting: [],
+    };
   },
 
   mounted() {
     // 监听子页面的消息
     if (typeof window.addEventListener != 'undefined') {
-      window.addEventListener('message', this.dealMessage, false)
+      window.addEventListener('message', this.dealMessage, false);
     } else if (typeof window.attachEvent != 'undefined') {
-      window.attachEvent('onmessage', this.dealMessage)
+      window.attachEvent('onmessage', this.dealMessage);
     }
-    this.queryWordPressConfig()
+    this.queryWordPressConfig();
   },
 
   methods: {
     dealMessage(e) {
       if (e.data.status == 2000) {
         if (!e.data.data['wp-auth-check']) {
-          this.src = ''
-          this.queryWordPressConfig()
+          this.src = '';
+          this.queryWordPressConfig();
         }
       }
     },
     // 调用方法
     iframeLoad() {
       this.$nextTick(() => {
-        this.loading = true
-        const iframe = this.$refs.iframeCom.iframeRef
+        this.loading = true;
+        const iframe = this.$refs.iframeCom.iframeRef;
         //表示页面加载错误
-        this.pageError = true
+        this.pageError = true;
 
         iframe.onload = () => {
-          this.loading = false
-        }
-      })
-
+          this.loading = false;
+        };
+      });
     },
 
     async queryWordPressConfig() {
-      let that = this
-      that.wordpressSwitch = ''
-      that.pageError = false
-      let url = ''
+      let that = this;
+      that.wordpressSwitch = '';
+      that.pageError = false;
+      let url = '';
       let params = {
         siteCode: localStorage.getItem('siteCode'),
-      }
-      await postAction('/adweb/adwebSiteManage/queryWordPressConfig', params).then(function (res) {
+      };
+      await postAction('/adweb/adwebSiteManage/queryWordPressConfig', params)
+        .then(function (res) {
+          if (res.code === 200) {
+            that.wordpressSwitch = res.result.wordpressSwitch ? res.result.wordpressSwitch : 2;
+            if (res.result.wordpressSetting != null) {
+              that.wordpressSetting = res.result.wordpressSetting;
+            }
+            if (res.result.openSetting != null) {
+              that.openSetting = res.result.openSetting;
+            }
 
-        if (res.code === 200) {
+            if (res.result.productType === 'woocommerce') {
+              url = that.wooUrl ? that.wooUrl : that.url;
+            } else {
+              url = that.url;
+            }
 
-          that.wordpressSwitch = res.result.wordpressSwitch ? res.result.wordpressSwitch : 2
-          if (res.result.wordpressSetting != null) {
-            that.wordpressSetting = res.result.wordpressSetting
-          }
-          if (res.result.openSetting != null) {
-            that.openSetting = res.result.openSetting
-          }
+            let isIframe = 0;
+            if (that.wordpressSetting === 'all' || that.openSetting.includes(that.iframePage)) {
+              isIframe = 1;
+            }
 
-          if (res.result.productType == 'woocommerce') {
-            url = that.wooUrl ? that.wooUrl : that.url
-          }else{
-            url = that.url
-          }
+            if (that.parantEvent) {
+              that.parantEvent(res.result.wordpressSwitch);
+            }
 
-          let isIframe = 0
-          if (that.wordpressSwitch == 1 && (that.wordpressSetting == 'all' || that.openSetting.includes(that.iframePage))) {
-            isIframe = 1
+            if ((that.wordpressSetting === 'all' || that.openSetting.includes('product') || that.openSetting.includes('article')) && isIframe === 1) {
+              let domainUrl = res.result.domain;
+              let token = res.result.wordpressToken;
+              let username = res.result.wordpressName;
+              let page_no_login = domainUrl + '/wp-html.php?token=' + token + '&username=' + username + '&jumpUrl=' + encodeURIComponent(url);
+              // let page_ready =  domainUrl + "/wp-admin/"+ that.loginUrl +""
+              // let ssoResKey =  res.result.ssoResKey
+              // if(ssoResKey){
+              //   that.src =   page_ready
+              // }else{
+              that.src = page_no_login;
+              // }
+              that.iframeLoad();
+            }
           }
-
-          if (that.parantEvent) {
-            that.parantEvent(res.result.wordpressSwitch)
-          }
-
-          if (res.result.wordpressSwitch == 1 &&
-            (that.wordpressSetting == 'all' || that.openSetting.includes('product') || that.openSetting.includes('article')) &&
-            isIframe == 1) {
-            let domainUrl = res.result.domain
-            let token = res.result.wordpressToken
-            let username = res.result.wordpressName
-            let page_no_login = domainUrl + '/wp-html.php?token=' + token + '&username=' + username + '&jumpUrl=' + encodeURIComponent(url)
-            // let page_ready =  domainUrl + "/wp-admin/"+ that.loginUrl +""
-            // let ssoResKey =  res.result.ssoResKey
-            // if(ssoResKey){
-            //   that.src =   page_ready
-            // }else{
-            that.src = page_no_login
-            // }
-            that.iframeLoad()
-          }
-        }
-      }).catch((err) => {
-        console.log(err)
-        that.wordpressSwitch = '3'
-      })
+        })
+        .catch((err) => {
+          console.log(err);
+          that.wordpressSwitch = '3';
+        });
     },
-
-  }
-
-}
+  },
+};