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.

160 lines
3.8 KiB

2 years ago
<template>
<div>
2 years ago
<xy-dialog ref="dialog" :width="50" :is-show.sync="isShow" :type="'form'" :title="'二维码'" :form="form"
2 years ago
:rules='rules'>
<template v-slot:settings>
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold;width:0">
<span style="color: red;font-weight: bold;padding-right: 4px;"></span>
</div>
<div class="xy-table-item-content" style="flex-grow: 1;">
<div class="txl">
<div>
2 years ago
<div>课程名称{{row.name}}</div>
2 years ago
<div>开课日期{{row.start_date ? row.start_date + '至' + row.end_date : ''}}</div>
2 years ago
<div>课程体系{{row.type_value}}</div>
2 years ago
</div>
</div>
5 days ago
<div class="code">
<div v-if="imgSrc">
<img :src="imgSrc" />
</div>
<div v-else class="empty-code">
<p>{{ loading ? '加载中...' : '暂无二维码' }}</p>
<el-button
v-if="!loading"
type="primary"
:loading="generating"
@click="generateCode"
>生成二维码</el-button>
2 years ago
</div>
2 years ago
</div>
</div>
</div>
</template>
<template v-slot:footerContent>
2 years ago
<el-button type="primary" plain style='margin-left:5px;margin-bottom:5px;' @click="isShow=false"></el-button>
2 years ago
</template>
</xy-dialog>
</div>
</template>
5 days ago
<script>
2 years ago
import {getQrCode} from "@/api/course"
2 years ago
export default {
components: {
},
data() {
return {
isShow: false,
form: {
settings: '',
5 days ago
},
2 years ago
row:{},
5 days ago
rules: {},
imgSrc:'',
loading: false,
generating: false
2 years ago
}
},
created() {},
methods: {
2 years ago
async getCode() {
5 days ago
if (!this.row.id) {
this.imgSrc = ''
return
}
this.loading = true
this.imgSrc = ''
try {
// 仅查询已有二维码,不触发生成,避免打开弹窗即 500
const res = await getQrCode({
id: this.row.id,
generate: 0
}, false)
this.imgSrc = res.msg || ''
} catch (e) {
this.imgSrc = ''
} finally {
this.loading = false
}
},
async generateCode() {
if (!this.row.id || this.generating) {
return
}
this.generating = true
try {
const res = await getQrCode({
id: this.row.id,
generate: 1
})
this.imgSrc = res.msg || ''
if (this.imgSrc) {
this.$message.success('二维码生成成功')
}
} catch (e) {
// request 拦截器已提示错误
} finally {
this.generating = false
}
2 years ago
}
},
watch: {
isShow(newVal) {
5 days ago
if (newVal) {
2 years ago
this.getCode()
5 days ago
} else {
this.row = {}
2 years ago
this.imgSrc = ''
5 days ago
this.loading = false
this.generating = false
2 years ago
}
},
}
}
</script>
<style scoped lang="scss">
::v-deep .settings {
flex-basis: 100%;
}
.txl {
display: flex;
justify-content: center;
margin-bottom: 30px;
}
.code {
5 days ago
min-height: 200px;
2 years ago
text-align: center;
2 years ago
img {
width: 200px;
height: 200px;
2 years ago
}
}
5 days ago
.empty-code {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 200px;
p {
margin-bottom: 16px;
color: #909399;
}
}
</style>