<template>
|
<div class="app-container">
|
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
<el-form-item label="车牌号" prop="vehicleNo">
|
<el-input
|
v-model="queryParams.vehicleNo"
|
placeholder="请输入车牌号"
|
clearable
|
@keyup.enter.native="handleQuery"
|
/>
|
</el-form-item>
|
<el-form-item label="状态" prop="status">
|
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
|
<el-option label="正常" value="0" />
|
<el-option label="停用" value="1" />
|
</el-select>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
</el-form-item>
|
</el-form>
|
|
<el-row :gutter="10" class="mb8">
|
<el-col :span="1.5">
|
<el-button
|
type="primary"
|
plain
|
icon="el-icon-plus"
|
size="mini"
|
@click="handleAdd"
|
v-hasPermi="['evaluation:qrcode:generate']"
|
>生成二维码</el-button>
|
</el-col>
|
<el-col :span="1.5">
|
<el-button
|
type="success"
|
plain
|
icon="el-icon-upload2"
|
size="mini"
|
@click="handleBatchGenerate"
|
v-hasPermi="['evaluation:qrcode:batch']"
|
>批量生成</el-button>
|
</el-col>
|
<el-col :span="1.5">
|
<el-button
|
type="danger"
|
plain
|
icon="el-icon-delete"
|
size="mini"
|
:disabled="multiple"
|
@click="handleDelete"
|
v-hasPermi="['evaluation:qrcode:remove']"
|
>删除</el-button>
|
</el-col>
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
</el-row>
|
|
<el-table v-loading="loading" :data="qrcodeList" @selection-change="handleSelectionChange">
|
<el-table-column type="selection" width="55" align="center" />
|
|
<el-table-column label="车牌号" align="center" prop="vehicleNo" />
|
<el-table-column label="二维码URL" align="center" prop="qrcodeUrl" width="200">
|
<template slot-scope="scope">
|
<el-link :href="scope.row.qrcodeUrl" target="_blank" type="primary">{{ scope.row.qrcodeUrl }}</el-link>
|
</template>
|
</el-table-column>
|
<el-table-column label="二维码内容" align="center" prop="qrcodeContent" />
|
<el-table-column label="二维码图片" align="center" prop="qrcodeImage" width="100">
|
<template slot-scope="scope">
|
<el-image
|
v-if="scope.row.qrcodeImage"
|
:src="getImageUrl(scope.row.qrcodeImage)"
|
:preview-src-list="[getImageUrl(scope.row.qrcodeImage)]"
|
style="width: 50px; height: 50px;"
|
fit="cover">
|
</el-image>
|
</template>
|
</el-table-column>
|
<el-table-column label="状态" align="center" prop="status">
|
<template slot-scope="scope">
|
<dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
|
</template>
|
</el-table-column>
|
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
<template slot-scope="scope">
|
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<template slot-scope="scope">
|
<el-button
|
size="mini"
|
type="text"
|
icon="el-icon-view"
|
@click="handleView(scope.row)"
|
v-hasPermi="['evaluation:qrcode:query']"
|
>查看</el-button>
|
<el-button
|
size="mini"
|
type="text"
|
icon="el-icon-download"
|
@click="handleDownload(scope.row)"
|
>下载</el-button>
|
<el-button
|
size="mini"
|
type="text"
|
icon="el-icon-delete"
|
@click="handleDelete(scope.row)"
|
v-hasPermi="['evaluation:qrcode:remove']"
|
>删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<pagination
|
v-show="total>0"
|
:total="total"
|
:page.sync="queryParams.pageNum"
|
:limit.sync="queryParams.pageSize"
|
@pagination="getList"
|
/>
|
|
<!-- 生成二维码对话框 -->
|
<el-dialog title="生成二维码" :visible.sync="open" width="500px" append-to-body>
|
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
<el-form-item label="车牌号" prop="vehicleNo">
|
<el-input v-model="form.vehicleNo" placeholder="请输入车牌号" />
|
</el-form-item>
|
<el-form-item label="二维码URL" prop="qrcodeUrl">
|
<el-input v-model="form.qrcodeUrl" placeholder="可选,留空则使用默认URL" />
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
<el-button @click="cancel">取 消</el-button>
|
</div>
|
</el-dialog>
|
|
<!-- 批量生成二维码对话框 -->
|
<el-dialog title="批量生成二维码" :visible.sync="batchOpen" width="600px" append-to-body>
|
<el-form ref="batchForm" :model="batchForm" :rules="batchRules" label-width="100px">
|
<el-form-item label="车牌号" prop="vehicleNos">
|
<el-input
|
v-model="batchForm.vehicleNos"
|
type="textarea"
|
:rows="6"
|
placeholder="请输入车牌号,多个车牌号用逗号分隔,例如:粤A12345,粤B67890,粤C11111" />
|
</el-form-item>
|
<el-form-item label="二维码URL" prop="qrcodeUrl">
|
<el-input v-model="batchForm.qrcodeUrl" placeholder="可选,留空则使用默认URL" />
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button type="primary" @click="submitBatchForm">确 定</el-button>
|
<el-button @click="cancelBatch">取 消</el-button>
|
</div>
|
</el-dialog>
|
|
<!-- 二维码详情对话框 -->
|
<el-dialog title="二维码详情" :visible.sync="viewOpen" width="600px" append-to-body>
|
<el-descriptions :column="2" border>
|
|
<el-descriptions-item label="车牌号">{{ viewForm.vehicleNo }}</el-descriptions-item>
|
<el-descriptions-item label="二维码URL" :span="2">
|
<el-link :href="viewForm.qrcodeUrl" target="_blank" type="primary">{{ viewForm.qrcodeUrl }}</el-link>
|
</el-descriptions-item>
|
<el-descriptions-item label="二维码内容" :span="2">{{ viewForm.qrcodeContent }}</el-descriptions-item>
|
<el-descriptions-item label="状态">
|
<dict-tag :options="dict.type.sys_normal_disable" :value="viewForm.status"/>
|
</el-descriptions-item>
|
<el-descriptions-item label="创建时间">{{ parseTime(viewForm.createTime) }}</el-descriptions-item>
|
<el-descriptions-item label="二维码图片" :span="2">
|
<el-image
|
v-if="viewForm.qrcodeImage"
|
:src="getImageUrl(viewForm.qrcodeImage)"
|
style="width: 200px; height: 200px;"
|
fit="cover">
|
</el-image>
|
</el-descriptions-item>
|
</el-descriptions>
|
|
<div slot="footer" class="dialog-footer">
|
<el-button @click="viewOpen = false">关 闭</el-button>
|
<el-button type="primary" @click="handleDownload(viewForm)">下载二维码</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import { listQrcode, getQrcode, delQrcode, generateQrcode, batchGenerateQrcode } from "@/api/evaluation";
|
|
export default {
|
name: "VehicleEvaluationQrcode",
|
dicts: ['sys_normal_disable'],
|
data() {
|
return {
|
// 遮罩层
|
loading: true,
|
// 选中数组
|
ids: [],
|
// 非单个禁用
|
single: true,
|
// 非多个禁用
|
multiple: true,
|
// 显示搜索条件
|
showSearch: true,
|
// 总条数
|
total: 0,
|
// 车辆评价二维码表格数据
|
qrcodeList: [],
|
// 弹出层标题
|
title: "",
|
// 是否显示弹出层
|
open: false,
|
// 是否显示批量生成弹出层
|
batchOpen: false,
|
// 是否显示查看弹出层
|
viewOpen: false,
|
// 查询参数
|
queryParams: {
|
pageNum: 1,
|
pageSize: 10,
|
vehicleNo: null,
|
status: null
|
},
|
// 表单参数
|
form: {},
|
// 批量生成表单参数
|
batchForm: {},
|
// 查看表单参数
|
viewForm: {},
|
// 表单校验
|
rules: {
|
vehicleNo: [
|
{ required: true, message: "车牌号不能为空", trigger: "blur" }
|
],
|
qrcodeUrl: [
|
{ type: 'url', message: '请输入正确的URL格式', trigger: 'blur' }
|
]
|
},
|
// 批量生成表单校验
|
batchRules: {
|
vehicleNos: [
|
{ required: true, message: "车牌号不能为空", trigger: "blur" }
|
],
|
qrcodeUrl: [
|
{ type: 'url', message: '请输入正确的URL格式', trigger: 'blur' }
|
]
|
}
|
};
|
},
|
created() {
|
this.getList();
|
},
|
methods: {
|
/** 查询车辆评价二维码列表 */
|
getList() {
|
this.loading = true;
|
listQrcode(this.queryParams).then(response => {
|
this.qrcodeList = response.rows;
|
this.total = response.total;
|
this.loading = false;
|
});
|
},
|
// 取消按钮
|
cancel() {
|
this.open = false;
|
this.reset();
|
},
|
// 表单重置
|
reset() {
|
this.form = {
|
qrcodeId: null,
|
vehicleNo: null,
|
qrcodeUrl: null,
|
qrcodeContent: null,
|
qrcodeImage: null,
|
status: "0"
|
};
|
this.resetForm("form");
|
},
|
// 批量表单重置
|
resetBatch() {
|
this.batchForm = {
|
vehicleNos: null,
|
qrcodeUrl: null
|
};
|
this.resetForm("batchForm");
|
},
|
/** 搜索按钮操作 */
|
handleQuery() {
|
this.queryParams.pageNum = 1;
|
this.getList();
|
},
|
/** 重置按钮操作 */
|
resetQuery() {
|
this.resetForm("queryForm");
|
this.handleQuery();
|
},
|
// 多选框选中数据
|
handleSelectionChange(selection) {
|
this.ids = selection.map(item => item.qrcodeId)
|
this.single = selection.length!==1
|
this.multiple = !selection.length
|
},
|
/** 新增按钮操作 */
|
handleAdd() {
|
this.reset();
|
this.open = true;
|
this.title = "生成二维码";
|
},
|
/** 提交按钮 */
|
submitForm() {
|
this.$refs["form"].validate(valid => {
|
if (valid) {
|
const params = {
|
vehicleNo: this.form.vehicleNo,
|
qrcodeUrl: this.form.qrcodeUrl || null
|
};
|
generateQrcode(params).then(response => {
|
this.$modal.msgSuccess("生成成功");
|
this.open = false;
|
this.getList();
|
});
|
}
|
});
|
},
|
/** 批量生成按钮操作 */
|
handleBatchGenerate() {
|
this.resetBatch();
|
this.batchOpen = true;
|
},
|
// 取消批量生成
|
cancelBatch() {
|
this.batchOpen = false;
|
this.resetBatch();
|
},
|
/** 批量提交按钮 */
|
submitBatchForm() {
|
this.$refs["batchForm"].validate(valid => {
|
if (valid) {
|
const vehicleNos = this.batchForm.vehicleNos.split(',').map(no => no.trim()).filter(no => no);
|
if (vehicleNos.length === 0) {
|
this.$modal.msgError("请输入有效的车牌号");
|
return;
|
}
|
|
console.log('批量生成车牌号列表:', vehicleNos);
|
|
const params = {
|
vehicleNos: vehicleNos,
|
qrcodeUrl: this.batchForm.qrcodeUrl || null
|
};
|
|
console.log('批量生成参数:', params);
|
|
batchGenerateQrcode(params).then(response => {
|
console.log('批量生成响应:', response);
|
if (response.code === 200) {
|
this.$modal.msgSuccess(response.msg || "批量生成成功");
|
} else {
|
this.$modal.msgError(response.msg || "批量生成失败");
|
}
|
this.batchOpen = false;
|
this.getList();
|
}).catch(error => {
|
console.error('批量生成失败:', error);
|
this.$modal.msgError("批量生成失败,请重试");
|
});
|
}
|
});
|
},
|
/** 查看按钮操作 */
|
handleView(row) {
|
this.viewForm = row;
|
this.viewOpen = true;
|
},
|
/** 下载按钮操作 */
|
handleDownload(row) {
|
if (row.qrcodeImage) {
|
const link = document.createElement('a');
|
link.href = this.getImageUrl(row.qrcodeImage);
|
link.download = `qrcode_${row.vehicleNo}.png`;
|
link.click();
|
}
|
},
|
/** 删除按钮操作 */
|
handleDelete(row) {
|
const qrcodeIds = row.qrcodeId || this.ids;
|
this.$modal.confirm('是否确认删除车辆评价二维码编号为"' + qrcodeIds + '"的数据项?').then(function() {
|
return delQrcode(qrcodeIds);
|
}).then(() => {
|
this.getList();
|
this.$modal.msgSuccess("删除成功");
|
}).catch(() => {});
|
},
|
/** 获取图片URL */
|
getImageUrl(imagePath) {
|
if (imagePath) {
|
// 如果是base64格式,直接返回
|
if (imagePath.startsWith('data:image/')) {
|
return imagePath;
|
}
|
// 如果路径已经包含http,直接返回
|
if (imagePath.startsWith('http://') || imagePath.startsWith('https://')) {
|
return imagePath;
|
}
|
// 如果路径以/开头,直接拼接域名
|
if (imagePath.startsWith('/')) {
|
return process.env.VUE_APP_BASE_API + imagePath;
|
}
|
// 其他情况,添加/前缀后拼接域名
|
return process.env.VUE_APP_BASE_API + '/' + imagePath;
|
}
|
return '';
|
}
|
}
|
};
|
</script>
|