You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WeChat/src/views/modules/wx/wx-qrcode-add-or-update.vue

109 lines
4.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<!-- Element UI的对话框组件根据dataForm.id是否存在来设置标题为新增修改 -->
<el-dialog
:title="!dataForm.id ? '新增' : '修改'"
:close-on-click-modal="false" <!-- -->
:visible.sync="visible"> <!-- 双向绑定控制对话框的显示隐藏 -->
<!-- 表单部分绑定dataForm作为数据模型dataRule作为验证规则 -->
<el-form
:model="dataForm"
:rules="dataRule"
ref="dataForm"
@keyup.enter.native="dataFormSubmit()" <!-- Enter -->
label-width="100px">
<!-- 表单项二维码类型 -->
<el-form-item label="二维码类型" prop="isTemp">
<el-radio v-model="dataForm.isTemp" :label="true">临时</el-radio>
<el-radio v-model="dataForm.isTemp" :label="false"></el-radio>
<div>
<!-- 当不是临时二维码时显示链接 -->
<a class="text-warning" v-show="!dataForm.isTemp" target="_blank" href="https://developers.weixin.qq.com/doc/offiaccount/Account_Management/Generating_a_Parametric_QR_Code.html">
注意永久二维码上限10万个且暂时无法删除旧的二维码
</a>
</div>
</el-form-item>
<!-- 表单项:场景值 -->
<el-form-item label="场景值" prop="sceneStr">
<el-input v-model="dataForm.sceneStr" placeholder="任意字符串" maxlength="64"></el-input>
</el-form-item>
<!-- 表单项:失效时间(仅临时二维码显示) -->
<el-form-item label="失效时间/秒" prop="expireSeconds" v-if="dataForm.isTemp">
<el-input v-model="dataForm.expireSeconds" placeholder="单位最大259200030天"></el-input>
<div>最大30天当前设置<span class="text-warning">{{dataForm.expireSeconds/(24*3600)}}天</span></div>
</el-form-item>
</el-form>
<!-- 对话框底部按钮 -->
<span slot="footer" class="dialog-footer">
<el-button @click="visible = false">取消</el-button>
<el-button type="primary" @click="dataFormSubmit()"></el-button>
</span>
</el-dialog>
</template>
<script>
export default {
data() {
return {
visible: false, // 控制对话框显示隐藏
dataForm: {
isTemp: true, // 二维码类型:临时
sceneStr: '', // 场景值
expireSeconds: 2592000 // 失效时间默认30天
},
dataRule: {
isTemp: [
{ required: true, message: '二维码类型不能为空', trigger: 'blur' } // 验证规则
],
sceneStr: [
{ required: true, message: '场景值ID不能为空', trigger: 'blur' } // 验证规则
],
expireSeconds: [
{ required: true, message: '该二维码失效时间不能为空', trigger: 'blur' } // 验证规则(仅临时二维码需要)
]
}
}
},
methods: {
// 初始化方法传入id用于修改模式
init(id) {
this.dataForm.id = id || 0 // 设置dataForm的id属性
this.visible = true // 显示对话框
this.$nextTick(() => {
this.$refs['dataForm'].resetFields() // 重置表单
})
},
// 表单提交方法
dataFormSubmit() {
this.$refs['dataForm'].validate((valid) => {
if (valid) { // 表单验证通过
this.$http({ // 发送请求
url: this.$http.adornUrl(`/manage/wxQrCode/createTicket`), // 请求URL
method: 'post', // 请求方法
data: this.$http.adornData(this.dataForm) // 发送的数据
}).then(({ data }) => {
if (data && data.code === 200) { // 请求成功
this.$message({
message: '操作成功',
type: 'success',
duration: 1500,
onClose: () => {
this.visible = false // 关闭对话框
this.$emit('refreshDataList') // 通知父组件刷新数据列表
}
})
} else { // 请求失败
this.$message.error(data.msg) // 显示错误信息
}
})
}
})
}
}
}
</script>