|
@@ -0,0 +1,205 @@
|
|
|
+<template>
|
|
|
+ <a-drawer
|
|
|
+ :title="modalTitle"
|
|
|
+ :maskClosable="true"
|
|
|
+ width="850"
|
|
|
+ placement="right"
|
|
|
+ :closable="true"
|
|
|
+ @close="handleCancel"
|
|
|
+ :visible="modalVisible"
|
|
|
+ :ok-button-props="okBtnStatus"
|
|
|
+ destroy-on-close
|
|
|
+ style="overflow: auto; padding-bottom: 53px"
|
|
|
+ >
|
|
|
+ <!-- Gtm代码-->
|
|
|
+ <template v-if="modalGtmStatus">
|
|
|
+ <a-spin :spinning="spinning" :tip="tipTitle">
|
|
|
+ <a-button type="primary" @click="addGTMBySys" style="margin-right: 20px">系统添加</a-button>
|
|
|
+ <!-- <a-button class="manual-add" @click="addGTMByUser">手动添加</a-button>-->
|
|
|
+ </a-spin>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template v-if="modalSysAddGTMStatus">
|
|
|
+ <a-spin :spinning="spinning" :tip="tipTitle">
|
|
|
+ <a-form ref="ruleForm" :model="googleGtmForm" :label-col="labelCol" :wrapper-col="wrapperCol">
|
|
|
+ <div>
|
|
|
+ <p style="text-align: center; font-weight: bold">系统生成的跟踪代码已添加至网站,请勿重复添加跟踪代码。</p>
|
|
|
+ </div>
|
|
|
+ <a-form-item label="Gtm Head" prop="head">
|
|
|
+ <a-input v-model="googleGtmForm.head" id="googleGtmHead" type="textarea" :auto-size="{ minRows: 10, maxRows: 15 }" :readOnly="true" />
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="Gtm Body" prop="body">
|
|
|
+ <a-input v-model="googleGtmForm.body" id="googleGtmBody" type="textarea" :auto-size="{ minRows: 10, maxRows: 15 }" :readOnly="true" />
|
|
|
+ </a-form-item>
|
|
|
+ </a-form>
|
|
|
+ </a-spin>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template v-if="modalManualAddGTMStatus">
|
|
|
+ <a-spin :spinning="spinning" :tip="tipTitle">
|
|
|
+ <a-form ref="ruleForm" :model="googleGtmForm" :rules="googleGtmFormRules" :label-col="labelCol" :wrapper-col="wrapperCol">
|
|
|
+ <a-form-item label="Gtm Head" prop="head">
|
|
|
+ <a-input
|
|
|
+ v-model="googleGtmForm.head"
|
|
|
+ type="textarea"
|
|
|
+ placeholder="请输入Gtm跟踪代码 Head部分"
|
|
|
+ :auto-size="{ minRows: 10, maxRows: 15 }"
|
|
|
+ />
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="Gtm Body" prop="body">
|
|
|
+ <a-input
|
|
|
+ v-model="googleGtmForm.body"
|
|
|
+ type="textarea"
|
|
|
+ placeholder="请输入Gtm跟踪代码 Body部分"
|
|
|
+ :auto-size="{ minRows: 10, maxRows: 15 }"
|
|
|
+ />
|
|
|
+ </a-form-item>
|
|
|
+ </a-form>
|
|
|
+ </a-spin>
|
|
|
+ </template>
|
|
|
+ </a-drawer>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+ import { reactive, ref } from 'vue';
|
|
|
+ import { getAction } from '/@/api/manage/manage';
|
|
|
+ import { message } from 'ant-design-vue';
|
|
|
+
|
|
|
+ const modalTitle = ref('系统生成跟踪代码');
|
|
|
+
|
|
|
+ const labelCol = reactive({ span: 3 });
|
|
|
+ const wrapperCol = reactive({ span: 21 });
|
|
|
+ const spinning = ref(false);
|
|
|
+ const tipTitle = ref('');
|
|
|
+ const modalGtmStatus = ref(false);
|
|
|
+ const modalManualAddGTMStatus = ref(false);
|
|
|
+
|
|
|
+ const modalSysAddGTMStatus = ref(false);
|
|
|
+
|
|
|
+ const okBtnStatus = ref(true);
|
|
|
+ const modalVisible = ref(false);
|
|
|
+
|
|
|
+ let googleGtmForm = reactive({ head: '', body: '' });
|
|
|
+
|
|
|
+ const googleGtmFormRules = reactive({
|
|
|
+ head: [{ required: true, message: 'Gtm Head不能为空', trigger: 'blur' }],
|
|
|
+ body: [{ required: true, message: 'Gtm Body不能为空', trigger: 'blur' }],
|
|
|
+ });
|
|
|
+
|
|
|
+ function init(record) {
|
|
|
+ modalVisible.value = true;
|
|
|
+ addGTM(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加gtm
|
|
|
+ function addGTM(r) {
|
|
|
+ let params = {
|
|
|
+ id: r.id,
|
|
|
+ };
|
|
|
+ let gtmListUrl = `/gtm/list`;
|
|
|
+ getAction(gtmListUrl, params)
|
|
|
+ .then(function (res) {
|
|
|
+ if (res.code === 200) {
|
|
|
+ if (res.result.gtmHead != null && res.result.gtmBody != null) {
|
|
|
+ modalVisible.value = true;
|
|
|
+ modalTitle.value = '系统生成跟踪代码';
|
|
|
+ modalGtmStatus.value = false;
|
|
|
+ modalManualAddGTMStatus.value = false;
|
|
|
+ modalSysAddGTMStatus.value = true;
|
|
|
+ okBtnStatus.value = false;
|
|
|
+ googleGtmForm.head = res.result.gtmHead;
|
|
|
+ googleGtmForm.body = res.result.gtmBody;
|
|
|
+ } else {
|
|
|
+ modalVisible.value = true;
|
|
|
+ modalTitle.value = '添加跟踪代码';
|
|
|
+ modalGtmStatus.value = true;
|
|
|
+ modalManualAddGTMStatus.value = false;
|
|
|
+ modalSysAddGTMStatus.value = false;
|
|
|
+ okBtnStatus.value = false;
|
|
|
+ }
|
|
|
+ } else if (res.code == 102) {
|
|
|
+ message.warning('该网站已分配GA账号,不可生成跟踪代码!');
|
|
|
+ } else {
|
|
|
+ message.error('系统异常,请重试!');
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(function (err) {
|
|
|
+ cleanAllFormData();
|
|
|
+ message.error('网络超时,请重试!');
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function handleCancel() {
|
|
|
+ cleanAllFormData();
|
|
|
+ }
|
|
|
+
|
|
|
+ function cleanAllFormData() {
|
|
|
+ okBtnStatus.value = true;
|
|
|
+
|
|
|
+ spinning.value = false;
|
|
|
+ tipTitle.value = '';
|
|
|
+
|
|
|
+ modalVisible.value = false;
|
|
|
+ modalTitle.value = '';
|
|
|
+
|
|
|
+ modalGtmStatus.value = false;
|
|
|
+ googleGtmForm = {
|
|
|
+ head: '',
|
|
|
+ body: '',
|
|
|
+ };
|
|
|
+
|
|
|
+ modalSysAddGTMStatus.value = false;
|
|
|
+ modalManualAddGTMStatus.value = false;
|
|
|
+ modalGtmStatus.value = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ function addGTMBySys() {
|
|
|
+ let that = this;
|
|
|
+ modalVisible.value = false;
|
|
|
+ modalTitle.value = '';
|
|
|
+ modalGtmStatus.value = false;
|
|
|
+ modalManualAddGTMStatus.value = false;
|
|
|
+ modalSysAddGTMStatus.value = false;
|
|
|
+ let r = siteInfo;
|
|
|
+ tableLoading = true;
|
|
|
+ tableLoadingTip = '正在生成网站跟踪代码';
|
|
|
+ let params = {
|
|
|
+ siteId: r.id,
|
|
|
+ domain: r.domain,
|
|
|
+ domainName: r.name,
|
|
|
+ siteCert: r.siteCert,
|
|
|
+ sitePrivkey: r.sitePrivkey,
|
|
|
+ siteChain: r.siteChain,
|
|
|
+ };
|
|
|
+ let gtmAddUrl = `${url.gtmAddUrl}`;
|
|
|
+ postAction(gtmAddUrl, Qs.stringify(params), 1000 * 60 * 5)
|
|
|
+ .then(function (res) {
|
|
|
+ tableLoading = false;
|
|
|
+ tableLoadingTip = '';
|
|
|
+ if (res.code == 200) {
|
|
|
+ $message.success('跟踪代码已生成并已添加至网站,请重新发布网站,查看跟踪代码安装情况!');
|
|
|
+ modalVisible.value = true;
|
|
|
+ modalTitle.value = 'GTM网站跟踪代码';
|
|
|
+ modalGtmStatus.value = false;
|
|
|
+ modalSysAddGTMStatus.value = true;
|
|
|
+ modalManualAddGTMStatus.value = false;
|
|
|
+ googleGtmForm.head = res.data.gtmHead;
|
|
|
+ googleGtmForm.body = res.data.gtmBody;
|
|
|
+ loadingDrawerBtn = false;
|
|
|
+ } else if (res.code == 102) {
|
|
|
+ loadingDrawerBtn = false;
|
|
|
+ $message.warning('该网站已分配GA账号,不可生成跟踪代码!');
|
|
|
+ } else {
|
|
|
+ loadingDrawerBtn = false;
|
|
|
+ $message.error('网站跟踪代码生成失败!');
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(function () {
|
|
|
+ loadingDrawerBtn = false;
|
|
|
+ $message.error('网络超时,请重试!');
|
|
|
+ loadData();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ defineExpose({ init });
|
|
|
+</script>
|