Merge branch 'master' of http://47.99.164.66:3000/hzdyjs-xg/all-project
This commit is contained in:
commit
ea739d328b
19 files changed
+3510
-39
No files matched your search
@@ -0,0 +1,278 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
/**
|
||||
* 二维码管理 VO
|
||||
*/
|
||||
export interface QrCodeVO {
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
id?: string | number;
|
||||
|
||||
/**
|
||||
* 二维码名称
|
||||
*/
|
||||
codeName?: string;
|
||||
|
||||
/**
|
||||
* 二维码类型(1-招生报名)
|
||||
*/
|
||||
codeType?: number;
|
||||
|
||||
/**
|
||||
* 二维码内容(URL)
|
||||
*/
|
||||
qrContent?: string;
|
||||
|
||||
/**
|
||||
* 访问令牌
|
||||
*/
|
||||
accessToken?: string;
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
expireTime?: string;
|
||||
|
||||
/**
|
||||
* 最大使用次数(0-无限制)
|
||||
*/
|
||||
maxUsage?: number;
|
||||
|
||||
/**
|
||||
* 当前使用次数
|
||||
*/
|
||||
currentUsage?: number;
|
||||
|
||||
/**
|
||||
* 状态(0-禁用 1-启用)
|
||||
*/
|
||||
status?: number;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
createBy?: string | number;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
createTime?: string;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
updateBy?: string | number;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 二维码管理 BO
|
||||
*/
|
||||
export interface QrCodeBO {
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
id?: string | number;
|
||||
|
||||
/**
|
||||
* 二维码名称
|
||||
*/
|
||||
codeName?: string;
|
||||
|
||||
/**
|
||||
* 二维码类型(1-招生报名)
|
||||
*/
|
||||
codeType?: number;
|
||||
|
||||
/**
|
||||
* 二维码内容(URL)
|
||||
*/
|
||||
qrContent?: string;
|
||||
|
||||
/**
|
||||
* 访问令牌
|
||||
*/
|
||||
accessToken?: string;
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
expireTime?: string;
|
||||
|
||||
/**
|
||||
* 最大使用次数(0-无限制)
|
||||
*/
|
||||
maxUsage?: number;
|
||||
|
||||
/**
|
||||
* 当前使用次数
|
||||
*/
|
||||
currentUsage?: number;
|
||||
|
||||
/**
|
||||
* 状态(0-禁用 1-启用)
|
||||
*/
|
||||
status?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 二维码查询参数
|
||||
*/
|
||||
export interface QrCodeQuery {
|
||||
/**
|
||||
* 二维码名称
|
||||
*/
|
||||
codeName?: string;
|
||||
|
||||
/**
|
||||
* 二维码类型
|
||||
*/
|
||||
codeType?: number;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
status?: number;
|
||||
|
||||
/**
|
||||
* 创建时间范围
|
||||
*/
|
||||
params?: {
|
||||
beginTime?: string;
|
||||
endTime?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询二维码列表
|
||||
*/
|
||||
export function listQrCode(query?: QrCodeQuery) {
|
||||
return request({
|
||||
url: '/zsjy/qrcode/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询二维码详细
|
||||
*/
|
||||
export function getQrCode(id: string | number) {
|
||||
return request({
|
||||
url: '/zsjy/qrcode/' + id,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增二维码
|
||||
*/
|
||||
export function addQrCode(data: QrCodeBO) {
|
||||
return request({
|
||||
url: '/zsjy/qrcode',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改二维码
|
||||
*/
|
||||
export function updateQrCode(data: QrCodeBO) {
|
||||
return request({
|
||||
url: '/zsjy/qrcode',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除二维码
|
||||
*/
|
||||
export function delQrCode(ids: string | number | Array<string | number>) {
|
||||
return request({
|
||||
url: '/zsjy/qrcode/' + ids,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出二维码
|
||||
*/
|
||||
export function exportQrCode(query?: QrCodeQuery) {
|
||||
return request({
|
||||
url: '/zsjy/qrcode/export',
|
||||
method: 'post',
|
||||
data: query,
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证二维码Token有效性
|
||||
*/
|
||||
export function validateToken(token: string) {
|
||||
return request({
|
||||
url: '/zsjy/qrcode/validate/' + token,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据Token获取二维码信息
|
||||
*/
|
||||
export function getQrCodeByToken(token: string) {
|
||||
return request({
|
||||
url: '/zsjy/qrcode/token/' + token,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加二维码使用次数
|
||||
*/
|
||||
export function incrementUsage(id: string | number) {
|
||||
return request({
|
||||
url: '/zsjy/qrcode/increment/' + id,
|
||||
method: 'post'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成新的访问令牌
|
||||
*/
|
||||
export function generateToken() {
|
||||
return request({
|
||||
url: '/zsjy/qrcode/generate-token',
|
||||
method: 'post'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 二维码类型选项
|
||||
*/
|
||||
export const qrCodeTypeOptions = [
|
||||
{
|
||||
label: '招生报名',
|
||||
value: 1
|
||||
}
|
||||
]
|
||||
|
||||
/**
|
||||
* 状态选项
|
||||
*/
|
||||
export const statusOptions = [
|
||||
{
|
||||
label: '禁用',
|
||||
value: 0
|
||||
},
|
||||
{
|
||||
label: '启用',
|
||||
value: 1
|
||||
}
|
||||
]
|
||||
@@ -159,6 +159,20 @@
|
||||
<el-icon><Star /></el-icon>
|
||||
报考信息
|
||||
</h3>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="所属学院" prop="collegeName" required>
|
||||
<el-select v-model="collegeSelectValue" placeholder="请选择所属学院" style="width: 100%" @change="onCollegeChange">
|
||||
<el-option v-for="college in collegeOptions" :key="college.deptId" :label="college.deptName" :value="college.deptId" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="学院代码" prop="collegeId">
|
||||
<el-input v-model="applyForm.collegeId" placeholder="学院代码将自动填入" readonly />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="报考专业" prop="appliedMajor" required>
|
||||
@@ -271,17 +285,20 @@
|
||||
import { reactive, ref, toRefs, getCurrentInstance, ComponentInternalInstance, onMounted, nextTick } from 'vue';
|
||||
import { ElForm } from 'element-plus';
|
||||
import { submitEnrollmentApplication, queryMyEnrollmentStatus } from '@/api/zsjy/enrollment';
|
||||
import { EnrollmentInfoForm } from '@/api/zsjy/enrollment/types';
|
||||
import type { EnrollmentInfoForm } from '@/api/zsjy/enrollment/types';
|
||||
import { listColleges, listMajorsByCollegeId } from '@/api/xg/xsjcxx/classMsg/college';
|
||||
import { User, School, Star, Document, Check, Refresh } from '@element-plus/icons-vue';
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
const { zsjy_gender, sys_yes_no, zsjy_major, zsjy_uniform_size } = toRefs<any>(
|
||||
proxy?.useDict('zsjy_gender', 'sys_yes_no', 'zsjy_major', 'zsjy_uniform_size')
|
||||
(proxy as any)?.useDict('zsjy_gender', 'sys_yes_no', 'zsjy_major', 'zsjy_uniform_size')
|
||||
);
|
||||
|
||||
const applyFormRef = ref<InstanceType<typeof ElForm>>();
|
||||
const submitLoading = ref(false);
|
||||
const queryLoading = ref(false);
|
||||
const collegeOptions = ref<Array<{ deptId: number; deptName: string; deptCategory: string }>>([]);
|
||||
const collegeSelectValue = ref<number | undefined>(undefined);
|
||||
const majorOptions = ref<Array<{ value: string; label: string; majorCode: string }>>([]);
|
||||
|
||||
const statusDialog = reactive({
|
||||
@@ -311,6 +328,8 @@ const applyForm = reactive<EnrollmentInfoForm>({
|
||||
scienceScore: undefined,
|
||||
socialScore: undefined,
|
||||
peScore: undefined,
|
||||
collegeName: undefined,
|
||||
collegeId: undefined,
|
||||
appliedMajor: undefined,
|
||||
majorCode: undefined,
|
||||
uniformSize: undefined,
|
||||
@@ -340,6 +359,7 @@ const rules = {
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '手机号码格式不正确', trigger: 'blur' }
|
||||
],
|
||||
phone2: [{ pattern: /^1[3-9]\d{9}$/, message: '手机号码格式不正确', trigger: 'blur' }],
|
||||
collegeName: [{ required: true, message: '所属学院不能为空', trigger: 'change' }],
|
||||
appliedMajor: [{ required: true, message: '报考专业不能为空', trigger: 'change' }],
|
||||
totalScoreFull: [{ type: 'number', min: 100, max: 1000, message: '中考满分应在100-1000之间', trigger: 'blur' }],
|
||||
totalScore: [{ type: 'number', min: 0, message: '中考成绩不能小于0', trigger: 'blur' }],
|
||||
@@ -383,6 +403,55 @@ const onIdCardChange = () => {
|
||||
}
|
||||
};
|
||||
|
||||
/** 学院选择变化处理 */
|
||||
const onCollegeChange = async (selectedCollegeId: number) => {
|
||||
if (selectedCollegeId) {
|
||||
// 根据选择的学院ID找到学院对象
|
||||
const college = collegeOptions.value.find((item) => item.deptId === selectedCollegeId);
|
||||
if (college) {
|
||||
// 设置学院信息
|
||||
applyForm.collegeId = college.deptCategory || college.deptId.toString();
|
||||
applyForm.collegeName = college.deptName;
|
||||
|
||||
// 根据学院加载专业选项
|
||||
await loadMajorsByCollegeId(selectedCollegeId);
|
||||
|
||||
// 清空专业选择
|
||||
applyForm.appliedMajor = undefined;
|
||||
applyForm.majorCode = undefined;
|
||||
|
||||
console.log('学院选择变化:', {
|
||||
collegeId: applyForm.collegeId,
|
||||
collegeName: applyForm.collegeName
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// 清空学院和专业相关字段
|
||||
applyForm.collegeName = undefined;
|
||||
applyForm.collegeId = undefined;
|
||||
applyForm.appliedMajor = undefined;
|
||||
applyForm.majorCode = undefined;
|
||||
majorOptions.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
/** 根据学院ID加载专业 */
|
||||
const loadMajorsByCollegeId = async (collegeId: number) => {
|
||||
try {
|
||||
const response = await listMajorsByCollegeId(collegeId);
|
||||
if (response.data) {
|
||||
majorOptions.value = response.data.map((major: any) => ({
|
||||
value: major.deptId.toString(),
|
||||
label: major.deptName,
|
||||
majorCode: major.deptCategory || major.deptId.toString()
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载专业数据失败:', error);
|
||||
majorOptions.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
/** 专业选择变化处理 */
|
||||
const onMajorChange = (selectedMajor: string) => {
|
||||
const major = majorOptions.value.find((item) => item.label === selectedMajor);
|
||||
@@ -448,10 +517,10 @@ const submitApplication = () => {
|
||||
}
|
||||
|
||||
await submitEnrollmentApplication(applyForm);
|
||||
proxy?.$modal.msgSuccess('报名申请提交成功!');
|
||||
(proxy as any)?.$modal.msgSuccess('报名申请提交成功!');
|
||||
resetForm();
|
||||
} catch (error) {
|
||||
proxy?.$modal.msgError('提交失败,请稍后重试');
|
||||
(proxy as any)?.$modal.msgError('提交失败,请稍后重试');
|
||||
} finally {
|
||||
submitLoading.value = false;
|
||||
}
|
||||
@@ -470,7 +539,7 @@ const resetForm = () => {
|
||||
/** 查询报名状态 */
|
||||
const queryStatus = async () => {
|
||||
if (!queryForm.idCard && !queryForm.examNumber) {
|
||||
proxy?.$modal.msgWarning('请输入身份证号或准考证号');
|
||||
(proxy as any)?.$modal.msgWarning('请输入身份证号或准考证号');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -485,16 +554,31 @@ const queryStatus = async () => {
|
||||
statusInfo.value = response.data;
|
||||
statusDialog.visible = true;
|
||||
} else {
|
||||
proxy?.$modal.msgWarning('未找到相关报名信息');
|
||||
(proxy as any)?.$modal.msgWarning('未找到相关报名信息');
|
||||
}
|
||||
} catch (error) {
|
||||
proxy?.$modal.msgError('查询失败,请稍后重试');
|
||||
(proxy as any)?.$modal.msgError('查询失败,请稍后重试');
|
||||
} finally {
|
||||
queryLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 获取学院选项 */
|
||||
const getCollegeOptions = async () => {
|
||||
try {
|
||||
const response = await listColleges();
|
||||
if (response.data) {
|
||||
collegeOptions.value = response.data;
|
||||
console.log('学院数据加载成功:', collegeOptions.value);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('学院数据加载失败:', error);
|
||||
collegeOptions.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getCollegeOptions();
|
||||
getMajorOptions();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -365,15 +365,7 @@
|
||||
<el-col :span="12">
|
||||
<el-form-item label="校服尺码" prop="uniformSize">
|
||||
<el-select v-model="form.uniformSize" placeholder="请选择校服尺码" style="width: 100%">
|
||||
<el-option value="150/84A" label="150/84A(身高150cm)" />
|
||||
<el-option value="155/86A" label="155/86A(身高155cm)" />
|
||||
<el-option value="160/88A" label="160/88A(身高160cm)" />
|
||||
<el-option value="165/90A" label="165/90A(身高165cm)" />
|
||||
<el-option value="170/92A" label="170/92A(身高170cm)" />
|
||||
<el-option value="175/94A" label="175/94A(身高175cm)" />
|
||||
<el-option value="180/96A" label="180/96A(身高180cm)" />
|
||||
<el-option value="185/98A" label="185/98A(身高185cm)" />
|
||||
<el-option value="190/100A" label="190/100A(身高190cm)" />
|
||||
<el-option v-for="dict in zsjy_uniform_size" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@@ -1214,18 +1206,7 @@ const onSearchCollegeChange = (selectedCollegeId: string) => {
|
||||
|
||||
// 专业选项由学院选择后动态生成
|
||||
|
||||
// 校服尺码数据,全局常量
|
||||
const UNIFORM_SIZES = [
|
||||
{ value: '150/84A', label: '150/84A(身高150cm)', height: '150cm' },
|
||||
{ value: '155/86A', label: '155/86A(身高155cm)', height: '155cm' },
|
||||
{ value: '160/88A', label: '160/88A(身高160cm)', height: '160cm' },
|
||||
{ value: '165/90A', label: '165/90A(身高165cm)', height: '165cm' },
|
||||
{ value: '170/92A', label: '170/92A(身高170cm)', height: '170cm' },
|
||||
{ value: '175/94A', label: '175/94A(身高175cm)', height: '175cm' },
|
||||
{ value: '180/96A', label: '180/96A(身高180cm)', height: '180cm' },
|
||||
{ value: '185/98A', label: '185/98A(身高185cm)', height: '185cm' },
|
||||
{ value: '190/100A', label: '190/100A(身高190cm)', height: '190cm' }
|
||||
];
|
||||
// 校服尺码数据使用字典 zsjy_uniform_size
|
||||
|
||||
/** 根据学院代码查找学院名称 */
|
||||
const getCollegeName = (code: string | undefined) => {
|
||||
@@ -1281,7 +1262,8 @@ const getCollegeNameEnhanced = (student: any) => {
|
||||
/** 获取校服尺码显示名称 */
|
||||
const getUniformSizeLabel = (value: string | undefined) => {
|
||||
if (!value) return '-';
|
||||
const size = UNIFORM_SIZES.find((item) => item.value === value);
|
||||
// 使用字典数据查找校服尺码
|
||||
const size = zsjy_uniform_size.value?.find((item: any) => item.value === value);
|
||||
return size ? size.label : value;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,332 @@
|
||||
<template>
|
||||
<div class="p-2 page-container" v-hasPermi="['zsjy:qrcode:view']">
|
||||
<!-- 二维码展示卡片 -->
|
||||
<el-card shadow="never" class="qrcode-card">
|
||||
<div class="qrcode-content">
|
||||
<!-- 页面标题 -->
|
||||
<div class="qrcode-header">
|
||||
<h2 class="qrcode-title">新生报名二维码</h2>
|
||||
<p class="qrcode-description">请扫码进行新生报名信息填写</p>
|
||||
</div>
|
||||
|
||||
<!-- 二维码区域 -->
|
||||
<div class="qrcode-wrapper">
|
||||
<div class="qrcode-container">
|
||||
<canvas ref="qrcodeCanvas" class="qrcode-canvas"></canvas>
|
||||
</div>
|
||||
|
||||
<!-- 二维码URL显示 -->
|
||||
<div class="qrcode-url">
|
||||
<el-input
|
||||
v-model="qrcodeUrl"
|
||||
placeholder="请输入二维码链接地址"
|
||||
clearable
|
||||
@change="generateQrcode"
|
||||
>
|
||||
<template #prepend>链接地址</template>
|
||||
</el-input>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<div class="qrcode-actions">
|
||||
<el-button
|
||||
type="primary"
|
||||
icon="Refresh"
|
||||
@click="generateQrcode"
|
||||
:loading="generating"
|
||||
v-hasPermi="['zsjy:qrcode:view']"
|
||||
>
|
||||
重新生成
|
||||
</el-button>
|
||||
<el-button
|
||||
type="success"
|
||||
icon="Download"
|
||||
@click="downloadQrcode"
|
||||
:disabled="!qrcodeGenerated"
|
||||
v-hasPermi="['zsjy:qrcode:view']"
|
||||
>
|
||||
下载二维码
|
||||
</el-button>
|
||||
<el-button
|
||||
type="info"
|
||||
icon="Printer"
|
||||
@click="printQrcode"
|
||||
:disabled="!qrcodeGenerated"
|
||||
v-hasPermi="['zsjy:qrcode:view']"
|
||||
>
|
||||
打印二维码
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="QrCode">
|
||||
import { ref, onMounted, nextTick, getCurrentInstance } from 'vue'
|
||||
import QRCode from 'qrcode'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
const { proxy } = getCurrentInstance() as any
|
||||
|
||||
// 响应式数据
|
||||
const qrcodeCanvas = ref<HTMLCanvasElement>()
|
||||
const qrcodeUrl = ref<string>('') // 二维码链接地址,可手动配置
|
||||
const generating = ref<boolean>(false)
|
||||
const qrcodeGenerated = ref<boolean>(false)
|
||||
|
||||
// 默认二维码URL(后续可手动配置)
|
||||
const getDefaultUrl = () => {
|
||||
// 使用 window.location 来判断环境
|
||||
const isProduction = window.location.hostname !== 'localhost'
|
||||
return isProduction
|
||||
? 'https://domain.com/mobile/#/pages/enrollment/form'
|
||||
: 'http://localhost:8081/#/pages/enrollment/form'
|
||||
}
|
||||
|
||||
/** 生成二维码 */
|
||||
const generateQrcode = async () => {
|
||||
if (!qrcodeUrl.value.trim()) {
|
||||
ElMessage.warning('请输入有效的链接地址')
|
||||
return
|
||||
}
|
||||
|
||||
generating.value = true
|
||||
try {
|
||||
await nextTick()
|
||||
|
||||
if (qrcodeCanvas.value) {
|
||||
// 生成二维码到canvas
|
||||
await QRCode.toCanvas(qrcodeCanvas.value, qrcodeUrl.value, {
|
||||
width: 200,
|
||||
margin: 2,
|
||||
color: {
|
||||
dark: '#000000',
|
||||
light: '#FFFFFF'
|
||||
},
|
||||
errorCorrectionLevel: 'M'
|
||||
})
|
||||
|
||||
qrcodeGenerated.value = true
|
||||
ElMessage.success('二维码生成成功')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('生成二维码失败:', error)
|
||||
ElMessage.error('生成二维码失败,请检查链接地址是否正确')
|
||||
} finally {
|
||||
generating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 下载二维码 */
|
||||
const downloadQrcode = () => {
|
||||
if (!qrcodeCanvas.value || !qrcodeGenerated.value) {
|
||||
ElMessage.warning('请先生成二维码')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// 创建下载链接
|
||||
const link = document.createElement('a')
|
||||
link.download = `新生报到二维码_${new Date().getTime()}.png`
|
||||
link.href = qrcodeCanvas.value.toDataURL('image/png')
|
||||
|
||||
// 触发下载
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
|
||||
ElMessage.success('二维码下载成功')
|
||||
} catch (error) {
|
||||
console.error('下载二维码失败:', error)
|
||||
ElMessage.error('下载失败')
|
||||
}
|
||||
}
|
||||
|
||||
/** 打印二维码 */
|
||||
const printQrcode = () => {
|
||||
if (!qrcodeCanvas.value || !qrcodeGenerated.value) {
|
||||
ElMessage.warning('请先生成二维码')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// 创建打印窗口
|
||||
const printWindow = window.open('', '_blank')
|
||||
if (!printWindow) {
|
||||
ElMessage.error('无法打开打印窗口,请检查浏览器设置')
|
||||
return
|
||||
}
|
||||
|
||||
// 获取二维码图片数据
|
||||
const qrcodeDataUrl = qrcodeCanvas.value.toDataURL('image/png')
|
||||
|
||||
// 生成打印页面HTML
|
||||
const scriptTag = 'script'
|
||||
const printContent = [
|
||||
'<!DOCTYPE html>',
|
||||
'<html>',
|
||||
'<head>',
|
||||
'<meta charset="utf-8">',
|
||||
'<title>新生报到二维码</title>',
|
||||
'<style>',
|
||||
'body { margin: 0; padding: 20px; text-align: center; font-family: Arial, sans-serif; }',
|
||||
'.print-header { margin-bottom: 30px; }',
|
||||
'.print-title { font-size: 24px; font-weight: bold; color: #333; margin-bottom: 10px; }',
|
||||
'.print-description { font-size: 16px; color: #666; margin-bottom: 20px; }',
|
||||
'.print-qrcode { margin: 30px 0; }',
|
||||
'.print-qrcode img { border: 1px solid #ddd; padding: 10px; background: white; }',
|
||||
'@media print { body { margin: 0; } }',
|
||||
'</style>',
|
||||
'</head>',
|
||||
'<body>',
|
||||
'<div class="print-header">',
|
||||
'<h1 class="print-title">新生报到二维码</h1>',
|
||||
'<p class="print-description">请扫码进行新生报名信息填写</p>',
|
||||
'</div>',
|
||||
'<div class="print-qrcode">',
|
||||
`<img src="${qrcodeDataUrl}" alt="新生报到二维码" />`,
|
||||
'</div>',
|
||||
`<${scriptTag}>`,
|
||||
'window.onload = function() {',
|
||||
'window.print();',
|
||||
'window.onafterprint = function() { window.close(); }',
|
||||
'}',
|
||||
`</${scriptTag}>`,
|
||||
'</body>',
|
||||
'</html>'
|
||||
].join('')
|
||||
|
||||
// 写入打印内容
|
||||
printWindow.document.write(printContent)
|
||||
printWindow.document.close()
|
||||
|
||||
} catch (error) {
|
||||
console.error('打印二维码失败:', error)
|
||||
ElMessage.error('打印失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 组件挂载后初始化
|
||||
onMounted(() => {
|
||||
// 设置默认URL
|
||||
qrcodeUrl.value = getDefaultUrl()
|
||||
// 自动生成二维码
|
||||
nextTick(() => {
|
||||
generateQrcode()
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.page-container {
|
||||
.qrcode-card {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
|
||||
.qrcode-content {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.qrcode-header {
|
||||
margin-bottom: 40px;
|
||||
|
||||
.qrcode-title {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
margin-bottom: 12px;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.qrcode-description {
|
||||
font-size: 16px;
|
||||
color: #606266;
|
||||
margin-bottom: 0;
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.qrcode-wrapper {
|
||||
margin-bottom: 40px;
|
||||
|
||||
.qrcode-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
padding: 20px;
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
border: 2px dashed #e4e7ed;
|
||||
transition: all 0.3s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: #409eff;
|
||||
background-color: #f0f9ff;
|
||||
}
|
||||
|
||||
.qrcode-canvas {
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.qrcode-url {
|
||||
max-width: 400px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
}
|
||||
|
||||
.qrcode-actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.el-button {
|
||||
min-width: 120px;
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 响应式设计
|
||||
@media (max-width: 768px) {
|
||||
.page-container {
|
||||
.qrcode-card {
|
||||
margin: 0;
|
||||
|
||||
.qrcode-content {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.qrcode-header {
|
||||
margin-bottom: 30px;
|
||||
|
||||
.qrcode-title {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.qrcode-description {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
.qrcode-actions {
|
||||
.el-button {
|
||||
min-width: 100px;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user