You need to sign in or sign up before continuing.
index.vue 10.8 KB
<template>
  <div class="short-link-container">
    <div class="title">小程序短链</div>
    <div class="wrapper">
      <glsxCombiForm :isInline="false" :formRules="editRule" labelWidth="154px" defaultWidth="474px" :formObj="editForm" :formData="editFormDataPro">
        <div slot="tip" class="tip_widget">
          <div class="left">常用页面路径:</div>
          <div class="right">
            <div v-for="(item, index) in tipList" :key="index" class="right_page_title">{{ item.confName }}:{{ item.confId }}</div>
          </div>
        </div>
        <div slot="btn" class="btn_wrap">
            <el-button size="medium " @click="resetParam">重置</el-button>
            <el-button size="medium " :disabled="btnDisable" type="primary" @click="comfirmShortLink">生成短链</el-button>
        </div>
        <div v-if="shortLink" slot="links" class="link_wrap">{{shortLink}}</div>
      </glsxCombiForm>
    </div>
    <!-- <div v-if="shortLink" class="cell flex_sc">
      <div class="default_w">小程序短链</div>
      <el-input size="small" class="default_r_w" :value="shortLink" disabled></el-input>
      <el-button class="copyBtn" size="small" type="primary" @click="copyLink">复制</el-button>
    </div> -->
  </div>
</template>
<script>
import glsxCombiForm from '@/components/glsx-combi-form'
const ENVVersion = ['trial', 'release']
const GH_MINI_APPID = 'wxfe82b8d65d07808f'
const DJ_MINI_APPID = 'wxe10067a63c1856ac'
const DJ_MINI_BEAT_APPID = 'wx9f91c1ec493eb425'
const ENVLIST = [
  {
    confId: 1,
    confName: '体验版'
  },
  {
    confId: 2,
    confName: '线上版'
  }
]
const MINI = [
  {
    confId: GH_MINI_APPID,
    confName: '广汇车生活'
  },
  {
    confId: DJ_MINI_APPID,
    confName: '车生活助手'
  },
  {
    confId: DJ_MINI_BEAT_APPID,
    confName: '嘀加智享车生活体验版'
  }
]
const MINIPAGELIST = [
  {
    confId: 'pages/tab/index/index',
    djConfId: 'pages/tab/shopMall/index',
    confName: '首页',
    pageType: 1,
    params:'tabIndex=0'
  },
  {
    confId: 'pages/tab/equity/equity',
    djConfId: 'pages/tab/shopMall/index',
    confName: '权益首页',
    pageType: 1,
    params:'tabIndex=1'
  },
  {
    confId: 'pages/tab/mall/mall',
    djConfId: 'pages/tab/shopMall/index',
    confName: '商城首页',
    pageType: 1,
    params:'tabIndex=2'
  },
  {
    confId: 'packageEquity/pages/freecard/freecard',
    djConfId: 'packageShopmall/packageEquity/pages/freecard/freecard',
    confName: '试用会员领取页',
    params:''
  },
  {
    confId: 'packageEquity/pages/reviceVip/reviceVip',
    djConfId: 'packageShopmall/packageEquity/pages/reviceVip/reviceVip',
    confName: '无忧会员领取页',
    params:''
  }
]
const cloneText = message => {
  let input = document.createElement('input')
  input.value = message
  document.body.appendChild(input)
  input.select()
  input.setSelectionRange(0, input.value.length), document.execCommand('Copy')
  document.body.removeChild(input)
}
export default {
  name: '',
  components: {
    glsxCombiForm
  },
  data() {
    return {
      shortLink: '',
      btnDisable: false,
      tipList: MINIPAGELIST,
      editForm: {
        env: '',
        miniPrograme: '',
        path: '',
        merchantId: '',
        query: ''
      },
      editFormDataPro: [
        {
          label: '小程序',
          name: 'miniPrograme',
          type: 'select',
          isClear: true,
          noFilter: true,
          optionId: 'confId',
          optionLabel: 'confName',
          optionList: MINI,
          changeAttr: val => {
            this.resetShortLink()
            this.resetPartQuery()
          }
        },
        {
          label: '小程序环境',
          name: 'env',
          type: 'select',
          isClear: true,
          noFilter: true,
          optionId: 'confId',
          optionLabel: 'confName',
          optionList: ENVLIST,
          isDisabled: false,
          changeAttr: val => {
            this.resetShortLink()
          }
        },
        {
          label: '小程序页面路径',
          name: 'path',
          type: 'input',
          isClear: true,
          inputBlur:(e)=>{
            let target = MINIPAGELIST.find(item => (item.confId==this.editForm.path && item.pageType==1))
            const href = window.location.host
            this.editForm.query = (target && this.editForm.miniPrograme!=GH_MINI_APPID) ? target.params : ''
            const queryTarget = this.editFormDataPro.find(item => item.name==='query')
            queryTarget.isDisabled = target && this.editForm.miniPrograme!=GH_MINI_APPID
          }
        },
        {
          label: '',
          name: 'tip',
          addHtml: 'tip'
        },
        {
          label: '商户号',
          name: 'merchantId',
          type: 'input',
          isClear: true,
          maxlength:8
        },
        {
          label: '页面参数',
          name: 'query',
          type: 'input',
          isClear: true,
          placeholder: '如:name=vendor&color=black',
        },
        {
          label: '',
          name: 'btn',
          addHtml: 'btn'
        },
        {
          label: '',
          name: 'links',
          addHtml: 'links'
        },
      ],
      editRule:{
        miniPrograme:[{ required: true, message: '请选择小程序', trigger: 'change' }],
        env:[{ required: true, message: '请选择小程序环境', trigger: 'change' }],
        path:[{ required: true, message: '请输入小程序页面路径', trigger: 'change' }],
        merchantId:[
          { required: true, message: '请输入小程序商户号', trigger: 'change' },
           {
            validator: (rule, value, callback) => {
              return /^[-\\+]?([0-9]+\\.?)?[0-9]{8}$/.test(value) ? callback() : callback(new Error('请输入8位数字'))
            },
            trigger: 'change'
          }
        ],
      }
    }
  },
  watch: {
    'editForm.merchantId'() {
      this.resetShortLink()
    },
    'editForm.query'() {
      this.resetShortLink()
    }
  },
  created(){
    // const href = window.location.host
    // this.tipList = href.indexOf('cgacar') != -1 ? [...MINIPAGELIST] : [...DJMINIPAGELIST]
  },
  mounted() {
  },
  methods: {
    // 切换小程序appID重置参数
    resetPartQuery(){
      this.editForm.path = ''
      this.editForm.query = ''
      this.editForm.env = ''
      this.editForm.merchantId = ''
      const queryTarget = this.editFormDataPro.find(item => item.name==='query')
      queryTarget.isDisabled = false
    },
    // 重置页面
    resetParam() {
      this.editForm = {
        env: '',
        miniPrograme: '',
        path: '',
        merchantId: '',
        query: ''
      }
      this.shortLink = ''
      this.editFormDataPro[1].isDisabled = false
      this.resetPartQuery()
    },
    resetShortLink() {
      this.shortLink = null
      this.btnDisable = false
    },
    // 自动匹配参数
    matchParams(path) {
      console.log(path)
      //   let para = {}

      //   let query = ''
      //   let arr = []
      //   for (let key in para) {
      //     arr.push(`${key}=${JSON.stringify(para[key])}`)
      //   }
      //   query = arr.join('&')
      //   this.editForm.query = query
    },
    comfirmShortLink() {
      const { env, miniPrograme, path, merchantId, storeCode, query } = this.editForm
      if (!miniPrograme) return this.toastMessage('请选择小程序')
      if (!env) return this.toastMessage('请选择环境')
      if (!path) return this.toastMessage('请输入小程序页面路径')
      if (!merchantId) return this.toastMessage('请输入商户号')
      if(merchantId.length<8)return this.toastMessage('请输入8位数的商户号')
      if(!(/^[-\\+]?([0-9]+\\.?)?[0-9]{8}$/.test(merchantId)))return this.toastMessage('请输入8位数字的商户号')
      let base_info = `merchantId=${merchantId}`
    //   if (miniPrograme == GH_MINI_APPID && !storeCode) return this.toastMessage('广汇小程序必须填入门店对应的sapCode')
    //   if (miniPrograme == GH_MINI_APPID && env == 3) return this.toastMessage('广汇小程序暂时没有预发布环境')
    //   if (storeCode) {
    //     base_info = `${base_info}&storeCode=${storeCode}`
    //   }
      let target = MINIPAGELIST.find(item => (item.confId==this.editForm.path && item.pageType==1))
      const href = window.location.host
      let otherPath = (target && this.editForm.miniPrograme!=GH_MINI_APPID) ? target.djConfId : path
      const params = {
        envVersion: ENVVersion[env - 1],
        appId: miniPrograme,
        param: `${base_info}${query ? '&' : ''}${query}`,
        path: otherPath,
        merchantId
      }
       this.$apis.orderApi.getShortLinkUUID(params).then(res=>{
        if(res.code==0){
            this.shortLink = res.data
             this.btnDisable = true
        }else{
            this.toastMessage(res.message)
        }
       })
      //   this.createShortLink(params).then(res => {
      //     if (res.code == 0) {
      //       this.shortLink = res.data
      //       this.btnDisable = true
      //     }
      //   })
      //   const qrPara = {
      //     appId: miniPrograme,
      //     qrcodeType,
      //     path,
      //     scene: query
      //   }
      //   if (!qrcodeType) return
      //   this.createQrCodeImage(qrPara).then(res => {
      //     if (res.code == 0) {
      //       this.qrcode = res.data
      //     }
      //   })
    },
    toastMessage(message, type = 3) {
      const MESSAGE = ['info', 'success', 'warning', 'error']
      this.$message({
        message,
        type: MESSAGE[type]
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.short-link-container {
  background: white;
  height: calc(100vh - 80px);
  .title {
    padding: 15px 20px;
    font-weight: 500;
    font-size: 16px;
    color: #333333;
    line-height: 28px;
    border-bottom: 1px solid #e5e5e5;
  }
  .wrapper {
    padding: 32px 19px;
    .tip_widget {
      width: 474px;
      background: #f9f9f9;
      border-radius: 4px;
      box-sizing: border-box;
      padding: 10px 20px;
      margin: 20px 0 0px 0;
      // display: flex;
      .left,
      .right_page_title {
        font-weight: 400;
        font-size: 12px;
        color: #666666;
      }
      .right_page_title {
        height: 20px;
      }
      .right,
      .left {
        line-height: 20px;
      }
    }
    .btn_wrap{
        display: flex;
    }
    .link_wrap{
        width: 474px;
        height: 80px;
        background: #F4F6FC;
        border-radius: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 400;
        font-size: 14px;
        color: #333333;
    }
  }
  /deep/ .el-form-item__label {
    padding-right: 0px !important;
  }
  /deep/ .el-form-item{
    margin-bottom: 20px !important;
  }
  /deep/ .el-form-item:nth-child(3) {
    margin-bottom: 0 !important;
  }
}
.flex_sc {
  display: flex;
  align-items: center;
}
</style>