生成二维码小程序和H5码

html代码:

html 复制代码
<el-table-column label="二维码">
  <template slot-scope="{ row }">
    <el-button type="primary" @click="showQrCode1(row)">查看</el-button>
  </template>
</el-table-column>

<el-dialog :close-on-click-modal="false" title="二维码" :visible.sync="qrCodeShow1" append-to-body>
  <div class="btns">
    <el-button type="primary" @click="showQrCode2(1)">H5码</el-button>
    <el-button type="primary" @click="showQrCode2(2)">小程序码</el-button>
  </div>
  <div>
    <div class="copy_main">
      <p>
        h5链接:
        <span id="inviteH5Code">{{ `${users.merchant.domain}/h5/#/pages/videoDetail/videoDetail?id=${qrCodeCurrentData.id}` }}</span> 
      </p>
      <el-button @click="copyData(0)" style="color: skyblue">复制</el-button>
    </div>
    <div class="copy_main">
      <p>
        小程序路径:
        <span id="invitePcCode">{{ `/pages/videoDetail/videoDetail?id=${qrCodeCurrentData.id}` }}</span>
      </p>
      <el-button @click="copyData(1)" style="color: skyblue">复制</el-button>
    </div>
  </div>
</el-dialog>

<el-dialog :close-on-click-modal="false" :title="qrCodeType == 1 ? 'H5码' : '小程序码'" width="500px" :visible.sync="qrCodeShow2" append-to-body>
  <div style="text-align: center" v-loading="qrCodeLoading">
    <vue-qr v-if="qrCodeType == 1" :logoSrc="users.merchant.logo" :logoScale="0.2" :text="qrCodeSrc" :size="300"></vue-qr>
    <div v-else>
      <img style="width: 60%" :src="users.hostUrl + qrCodeSrc" />
      <div style="margin-top: 10px">
        <el-button type="primary" @click="showQrCode2(2)">刷新二维码</el-button>
      </div>
    </div>
  </div>
</el-dialog>

js组件和变量:

javascript 复制代码
import vueQr from "vue-qr";

components: { vueQr }

qrCodeShow1: false,  // 二维码1显示
qrCodeShow2: false,  // 二维码2显示
qrCodeType: "",  // 二维码类型
qrCodeSrc: "",  // 二维码链接
qrCodeCurrentData: {},  // 详情
qrCodeLoading: false  // 二维码重新加载loading

js方法:

javascript 复制代码
/**
 * 显示二维码弹框1
 */
showQrCode1(row) {
  this.qrCodeShow1 = true;
  this.qrCodeCurrentData = row;
},
/**
 * 显示二维码弹框2
 */
async showQrCode2(type) {
  this.qrCodeType = type;
  switch (type) {
    case 1:
      this.qrCodeSrc = `${this.users.merchant.domain}/h5/#/pages/videoDetail/videoDetail?id=${this.qrCodeCurrentData.id}`;
      break;
    case 2:
      this.qrCodeLoading = true;
      let params = {
        path: `/pages/videoDetail/videoDetail?id=${this.qrCodeCurrentData.id}`
      }
      let res = await question.getCodeImg(params);
      if (res.code == 200) {
        this.qrCodeSrc = res.data.src;
      } else {
        this.$message.error("生成失败,请点击刷新二维码按钮重新生成");
      }
      this.qrCodeLoading = false;
      break;
  }
  this.qrCodeShow2 = true;
}
相关推荐
weixin_lynhgworld13 分钟前
剧本杀小程序系统开发:构建剧本杀社交新生态
小程序
说私域15 分钟前
基于定制开发开源 AI 智能名片 S2B2C 商城小程序的热点与人工下发策略研究
人工智能·小程序
weixin_lynhgworld16 分钟前
陪诊小程序系统开发:让就医不再是一件难事
小程序
晓得迷路了31 分钟前
栗子前端技术周刊第 94 期 - React Native 0.81、jQuery 4.0.0 RC1、Bun v1.2.20...
前端·javascript·react.js
江城开朗的豌豆31 分钟前
React Native 实战心得
javascript
前端小巷子32 分钟前
Vue 自定义指令
前端·vue.js·面试
江城开朗的豌豆39 分钟前
React状态更新踩坑记:我是这样优雅修改参数的
前端·javascript·react.js
阿珊和她的猫1 小时前
autofit.js: 自动调整HTML元素大小的JavaScript库
开发语言·javascript·html
Stringzhua1 小时前
Vue中的数据渲染【4】
css·vue.js·css3
阿珊和她的猫6 小时前
v-scale-scree: 根据屏幕尺寸缩放内容
开发语言·前端·javascript