Explorar el Código

选择账号生成GA代码

chenlei1231 hace 2 meses
padre
commit
84bf20b8d3
Se han modificado 1 ficheros con 19 adiciones y 25 borrados
  1. 19 25
      src/views/adweb/site/components/GtmAdd.vue

+ 19 - 25
src/views/adweb/site/components/GtmAdd.vue

@@ -44,9 +44,9 @@
         <a-form ref="ruleForm" :model="googleGtmForm" :label-col="labelCol" :wrapper-col="wrapperCol">
           <a-form-item v-if="gtmAddingStatus" label="GA账号" name="gaAccount">
             <a-select
+              allow-clear
               placeholder="请选择GA账号"
               style="text-align: left"
-              allowClear
               v-model:value="gaAccountID"
               :options="gaAccountsList"
               @change="changeAccount"
@@ -80,6 +80,7 @@
   import { reactive, ref } from 'vue';
   import { getAction, postActionForm } from '/@/api/manage/manage';
   import { useMessage } from '@/hooks/web/useMessage';
+
   const { createMessage } = useMessage();
 
   const modalTitle = ref('跟踪代码');
@@ -97,7 +98,7 @@
 
   let googleGtmForm = reactive({ head: '', body: '' });
   let gaAccountsList = reactive([{ displayName: '', id: '' }]);
-  const gaAccountID = ref('');
+  const gaAccountID = ref(null);
 
   function init(record) {
     modalVisible.value = true;
@@ -114,7 +115,7 @@
       .then((res) => {
         spinning.value = false;
 
-        if (0) {
+        if (res.code === 200 && res.result.gtmHead !== '' && res.result.gtmBody !== '') {
           googleGtmForm.head = res.result.gtmHead;
           googleGtmForm.body = res.result.gtmBody;
           gtmAddedStatus.value = true;
@@ -170,10 +171,8 @@
 
   function cleanAllFormData() {
     okBtnStatus.value = true;
-
     spinning.value = false;
     tipTitle.value = '';
-
     modalVisible.value = false;
     modalTitle.value = '';
     googleGtmForm = {
@@ -186,44 +185,39 @@
   }
 
   function addGTMBySys() {
-    modalVisible.value = false;
-    modalTitle.value = '';
-    gtmAddingStatus.value = false;
-    gtmAddedStatus.value = false;
-    loadingDrawerBtn.value = true;
-
-    if (gaAccountID.value === '') {
-      createMessage.info('请选择GA账号!');
+    if (gaAccountID.value == '' || gaAccountID.value == null) {
+      createMessage.info('请先选择GA账号!');
       return;
     }
 
     let params = {
       siteCode: siteInfo.code,
-      gaAccountId: siteInfo.domain,
+      gaAccountId: gaAccountID.value,
     };
+
+    loadingDrawerBtn.value = true;
+
     let gtmAddUrl = `/gtm/add`;
     spinning.value = true;
     postActionForm(gtmAddUrl, params, 300000)
       .then(function (res) {
         if (res.code == 200) {
           createMessage.success('跟踪代码已生成!');
-          modalVisible.value = true;
-          modalTitle.value = 'GTM网站跟踪代码';
-          gtmAddedStatus.value = true;
-          gtmAddingStatus.value = false;
-          googleGtmForm.head = res.data.gtmHead;
-          googleGtmForm.body = res.data.gtmBody;
-          loadingDrawerBtn.value = false;
-        } else if (res.code == 102) {
-          createMessage.warning('该网站已分配GA账号,不可生成跟踪代码!');
+
+          googleGtmForm.head = res.result.gtmHead;
+          googleGtmForm.body = res.result.gtmBody;
         } else {
           createMessage.error('网站跟踪代码生成失败!');
         }
         loadingDrawerBtn.value = false;
+        gtmAddedStatus.value = true;
+        gtmAddingStatus.value = false;
         spinning.value = false;
       })
-      .catch(function () {
-        createMessage.error('网络超时,请重试!');
+      .catch(function (e) {
+        console.log('生成GTM代码报错:', e.message(), e);
+        createMessage.error('网络超时,请重试');
+        spinning.value = false;
       });
   }