devicesmgt/sgzb-ui/src/views/store/label/labelBinding.vue

899 lines
27 KiB
Vue
Raw Normal View History

2023-12-12 13:36:08 +08:00
<template>
2024-01-22 09:18:46 +08:00
<div class="app-container" id="labelBinding">
2023-12-20 20:17:03 +08:00
<div style="z-index: 10000">
<div style="z-index: 10000">
<el-form
:model="queryParams"
ref="queryForm"
size="small"
:inline="true"
v-show="showSearch"
label-width="68px"
style="z-index: 10000"
2023-12-19 04:26:18 +08:00
>
2024-03-05 18:41:35 +08:00
<el-form-item label="关键字" prop="keyWord">
2023-12-20 20:17:03 +08:00
<el-input
2024-03-05 18:41:35 +08:00
v-model="queryParams.keyWord"
2023-12-20 20:17:03 +08:00
placeholder="请输入关键字"
clearable
style="width: 240px"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="设备类型" prop="typeId">
<el-select
v-model="queryParams.typeId"
placeholder="请选择设备类型"
clearable filterable
2023-12-20 20:17:03 +08:00
style="width: 240px"
2024-03-07 11:38:10 +08:00
@change="selectDevice"
2023-12-20 20:17:03 +08:00
>
<el-option
v-for="typeItem in typeList"
:key="typeItem.typeId"
:label="typeItem.typeName"
:value="typeItem.typeId"
/>
</el-select>
</el-form-item>
<el-form-item label="规格型号" prop="modelId">
<el-select
v-model="queryParams.modelId"
placeholder="请选择规格型号"
2024-03-07 11:38:10 +08:00
clearable filterable
2023-12-20 20:17:03 +08:00
style="width: 240px"
>
<el-option
v-for="model in modelList"
:key="model.typeId"
:label="model.typeName"
:value="model.typeId"
/>
</el-select>
</el-form-item>
2023-12-22 14:05:57 +08:00
<el-form-item label="绑定状态" prop="isBind">
2023-12-20 20:17:03 +08:00
<el-select
2023-12-22 14:05:57 +08:00
v-model="queryParams.isBind"
2023-12-20 20:17:03 +08:00
placeholder="请选择绑定状态"
clearable
2023-12-20 20:17:03 +08:00
style="width: 240px"
>
<el-option label="已绑定" value="1" />
<el-option label="未绑定" value="0" />
</el-select>
</el-form-item>
2023-12-12 13:36:08 +08:00
2023-12-20 20:17:03 +08:00
<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>
</div>
<el-row :gutter="10" class="mb8">
<!-- -->
<el-col :span="1.5">
<el-button
type="primary"
icon="el-icon-plus"
size="mini"
@click="handleBind"
:disabled="single"
>绑定</el-button
>
</el-col>
<!-- :disabled="single" -->
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="createLabel"
>标签生成</el-button
>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-plus"
size="mini"
:disabled="multiple"
@click="labelUpload"
>标签下载</el-button
>
</el-col>
2023-12-12 13:36:08 +08:00
2023-12-20 20:17:03 +08:00
<!-- <el-col :span="1.5">
2023-12-12 13:36:08 +08:00
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
>删除</el-button>
2023-12-19 04:26:18 +08:00
</el-col> -->
2023-12-20 20:17:03 +08:00
<!-- <el-col :span="1.5">
2023-12-12 13:36:08 +08:00
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
@click="handleExport"
>导出</el-button>
2023-12-19 04:26:18 +08:00
</el-col> -->
2023-12-12 13:36:08 +08:00
2023-12-20 20:17:03 +08:00
<right-toolbar
:showSearch.sync="showSearch"
@queryTable="getList"
></right-toolbar>
</el-row>
2023-12-12 13:36:08 +08:00
2023-12-20 20:17:03 +08:00
<el-table
v-loading="loading"
:data="labelList"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="序号" align="center" type="index" />
<el-table-column
label="标签类型"
align="center"
prop="name"
:show-overflow-tooltip="true"
/>
<el-table-column label="标签编号" align="center" prop="labelCode">
<template slot-scope="scope">
<span
style="color: blue; cursor: pointer"
@click="labelUploadCode(scope.row)"
>
{{ scope.row.labelCode }}</span
>
</template>
</el-table-column>
<el-table-column
label="物品种类"
align="center"
prop="kindName"
:show-overflow-tooltip="true"
/>
<el-table-column label="物品名称" align="center" prop="modelName" />
<el-table-column
label="规格型号"
align="center"
prop="typeName"
:show-overflow-tooltip="true"
/>
<el-table-column label="设备编码" align="center" prop="maCode" />
<el-table-column
label="绑定人员"
align="center"
prop="userName"
:show-overflow-tooltip="true"
/>
<el-table-column label="绑定时间" align="center" prop="bindTime" />
<el-table-column label="状态" align="center" prop="status">
<template slot-scope="scope">
2023-12-22 17:29:57 +08:00
<span>{{
scope.row.status == 0
? '未绑定'
: scope.row.status == 1
? '已绑定'
: scope.row.status == 2
? '已解绑'
: ''
}}</span>
2023-12-20 20:17:03 +08:00
<!-- <dict-tag
:options="dict.type.sys_normal_disable"
:value="scope.row.status"
/> -->
</template>
</el-table-column>
<el-table-column
label="操作"
align="center"
class-name="small-padding fixed-width"
>
<template slot-scope="scope">
<!-- <el-button
2023-12-12 13:36:08 +08:00
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
2023-12-19 04:26:18 +08:00
>编辑</el-button> -->
2023-12-22 14:05:57 +08:00
<!-- status 未绑定0 已绑定1 已解绑2 -->
<!-- isBind 不展示解绑0 展示解绑1 -->
2023-12-20 20:17:03 +08:00
<el-button
2023-12-22 18:26:50 +08:00
:disabled="
!(scope.row.status === '1' && scope.row.isBind === '1')
"
2023-12-20 20:17:03 +08:00
size="mini"
2024-01-12 10:07:35 +08:00
type="danger"
2023-12-20 20:17:03 +08:00
icon="el-icon-delete"
@click="handleDelete(scope.row)"
>解绑</el-button
>
</template>
</el-table-column>
</el-table>
2023-12-12 13:36:08 +08:00
2023-12-20 20:17:03 +08:00
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
</div>
2023-12-12 13:36:08 +08:00
<!-- 标签绑定对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="标签类型" prop="labelType">
2023-12-20 20:17:03 +08:00
<el-select
v-model="form.labelType"
placeholder="请选择标签类型"
style="width: 100%"
disabled
2023-12-20 20:17:03 +08:00
>
2023-12-19 04:26:18 +08:00
<el-option
v-for="item in labelTypeList"
:key="item.id"
:label="item.name"
:value="item.id"
2023-12-20 20:17:03 +08:00
v-if="item.status != '1'"
2023-12-19 04:26:18 +08:00
></el-option>
</el-select>
2023-12-20 20:17:03 +08:00
</el-form-item>
<el-form-item label="标签编号" prop="labelCode">
2023-12-20 20:17:03 +08:00
<el-select
v-model="form.labelCode"
placeholder="请选择标签编号"
style="width: 100%"
disabled
2023-12-20 20:17:03 +08:00
>
<el-option
v-for="item in labelCodeList"
:key="item.labelCode"
:label="item.labelCode"
:value="item.labelCode"
v-if="item.status != '1'"
></el-option>
</el-select>
<!-- <el-input v-model="form.labelCode" placeholder="请输入标签编号" /> -->
2023-12-12 13:36:08 +08:00
</el-form-item>
2023-12-22 17:13:57 +08:00
<el-form-item label="规格型号" prop="typeId">
<treeselect
v-model="form.typeId"
:options="deptOptions"
placeholder="请选择规格型号"
2023-12-24 00:15:02 +08:00
default-expand-all
@select="selectType"
:disable-branch-nodes="true"
2023-12-22 17:13:57 +08:00
/>
</el-form-item>
<el-form-item label="设备编码" prop="maCode">
<el-input
v-model="form.maCode"
placeholder="请输入设备编码,如NSJJ+类型编码+规格编码"
:clearable="true"
/>
2023-12-12 13:36:08 +08:00
</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>
<!-- 标签生成对话框 -->
2023-12-20 20:17:03 +08:00
<el-dialog
:title="title"
:visible.sync="createOpen"
width="500px"
append-to-body
>
2023-12-12 13:36:08 +08:00
<el-form ref="cform" :model="cform" :rules="crules" label-width="80px">
<el-form-item label="标签类型" prop="labelType">
2023-12-20 20:17:03 +08:00
<el-select
v-model="cform.labelType"
placeholder="请选择标签类型"
style="width: 100%"
2023-12-20 20:17:03 +08:00
>
<el-option
v-for="item in labelTypeList"
:key="item.id"
:label="item.name"
:value="item.id"
v-if="item.status != '1'"
></el-option>
</el-select>
<!-- <el-input v-model="cform.labelType" placeholder="请输入标签类型" /> -->
2023-12-12 13:36:08 +08:00
</el-form-item>
<el-form-item label="标签数量" prop="labelNum">
2023-12-20 20:17:03 +08:00
<el-input-number
style="width: 100%"
v-model="cform.labelNum"
controls-position="right"
:min="1"
:max="100"
placeholder="请输入标签数量"
></el-input-number>
2023-12-12 13:36:08 +08:00
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitCreate"> </el-button>
<el-button @click="cancelCreate"> </el-button>
</div>
</el-dialog>
<!-- 标签下载对话框 -->
2023-12-20 20:17:03 +08:00
<el-dialog
:title="title"
:visible.sync="uploadOpen"
width="500px"
append-to-body
>
2023-12-12 13:36:08 +08:00
<div style="text-align: center">
<div class="uploadImg">
2023-12-20 20:17:03 +08:00
<div id="qrcode" class="qrcode" ref="codeItem"></div>
2023-12-12 13:36:08 +08:00
<!-- <img src="" alt="">-->
</div>
2023-12-20 20:17:03 +08:00
<div class="maCode">设备编号{{ rowObj.maCode }}</div>
2023-12-12 13:36:08 +08:00
</div>
<div slot="footer" class="dialog-footer" style="text-align: center">
2023-12-20 20:17:03 +08:00
<el-button type="primary" @click="downloadCode"> </el-button>
2023-12-12 13:36:08 +08:00
</div>
</el-dialog>
2024-03-07 11:38:10 +08:00
<div style="background-color: transparent">
2023-12-21 17:54:28 +08:00
<div
id="qrCode"
v-for="(codeItem, codeIndex) in checkboxModel"
:key="codeIndex"
class="captureId"
v-show="codeId"
ref="QrcodePage"
style="
z-index: -1111111;
position: absolute;
top: 10px;
left: -99999;
width: 450px;
height: 475px;
background-size: cover;
"
></div>
2023-12-20 20:17:03 +08:00
<!-- <center style="text-align: center; font-size: 1.5625rem">
{{ codeVal }}
</center> -->
</div>
2023-12-12 13:36:08 +08:00
</div>
</template>
<script>
2024-03-07 11:38:10 +08:00
import {addMachine, delMachine, getMachine, listMachine, updateMachine,supplierInfoList,getListByMaType} from "@/api/store/tools";
2023-12-20 20:17:03 +08:00
import { listType, getType, delType, addType, updateType, refreshCache, } from "@/api/system/dict/type";
import { listLabelBind, addLabelBind, delLabelBind } from "@/api/store/label";
2023-12-19 04:26:18 +08:00
import { getTypeList } from "@/api/store/warehousing";
import user from '../../../store/modules/user'
2023-12-20 20:17:03 +08:00
import { unitTypeList, getMaMachineLabelApi, addMaMachineLabelApi } from "@/api/base/base";
import { v4 as uuidv4 } from 'uuid';
import html2canvas from "html2canvas";
import QRCode from 'qrcodejs2'
import JSZip from 'jszip'
import FileSaver from "file-saver"
2023-12-22 17:13:57 +08:00
import { getDeviceTypeTree } from "@/api/claimAndRefund/receive";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
2023-12-12 13:36:08 +08:00
export default {
2024-01-22 09:18:46 +08:00
name: "LabelBinding",
2023-12-12 13:36:08 +08:00
dicts: ['sys_normal_disable'],
2023-12-22 17:13:57 +08:00
components: { Treeselect },
2023-12-12 13:36:08 +08:00
data() {
return {
2023-12-22 17:13:57 +08:00
deptOptions: undefined,
2023-12-20 20:17:03 +08:00
rowObj: {},
userInfo: user.state,
2023-12-12 13:36:08 +08:00
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
typeList: [],
2023-12-19 04:26:18 +08:00
modelList: [],
// 字典表格数据
labelList: [],
//标签类型下拉
labelTypeList: [],
2023-12-20 20:17:03 +08:00
// 标签编号
labelCodeList: [],
2023-12-12 13:36:08 +08:00
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 日期范围
dateRange: [],
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
2023-12-22 14:05:57 +08:00
// labelType: undefined,
// labelCode: undefined,
// status: undefined
2023-12-12 13:36:08 +08:00
},
// 表单参数
form: {},
// 表单校验
rules: {
2023-12-22 17:13:57 +08:00
// labelType: [
// { required: true, message: "标签类型不能为空", trigger: "blur" }
// ],
// labelCode: [
// { required: true, message: "标签编号不能为空", trigger: "blur" }
// ],
typeId: [
{ required: true, message: "规格型号不能为空", trigger: "blur" }
2023-12-19 04:26:18 +08:00
],
maCode: [
{ required: true, message: "设备编码不能为空", trigger: "blur" }
],
2023-12-12 13:36:08 +08:00
},
//标签生成
2023-12-20 20:17:03 +08:00
createOpen: false,
2023-12-12 13:36:08 +08:00
cform: {},
crules: {
labelType: [
{ required: true, message: "标签类型不能为空", trigger: "blur" }
],
2023-12-20 20:17:03 +08:00
labelNum: [
2023-12-12 13:36:08 +08:00
{ required: true, message: "标签数量不能为空", trigger: "blur" }
]
},
//标签下载
2023-12-20 20:17:03 +08:00
uploadOpen: false,
deviceId: '',
selectionList: [],
checkboxModel: [], // 列表复选框
checked: false,
qrcodeArr: [],
codeVal: "",
codeId: true,
2023-12-22 14:05:57 +08:00
isShowQrCode: -1,
labelmaCode: '',
2023-12-12 13:36:08 +08:00
};
},
created() {
2023-12-19 04:26:18 +08:00
console.log(this.userInfo.id)
2023-12-12 13:36:08 +08:00
this.getList();
2023-12-19 04:26:18 +08:00
this.getType()
this.getTypeList();
2023-12-12 13:36:08 +08:00
},
methods: {
2023-12-20 20:17:03 +08:00
/** 查询下拉 */
getTypeList() {
getTypeList({ level: '3' }).then(response => {
this.typeList = response.data;
}
);
getTypeList({ level: '4' }).then(response => {
this.modelList = response.data;
}
);
},
//获取单位类型
getType() {
unitTypeList({ id: "8" }).then(response => {
this.labelTypeList = response.rows;
})
// 获取标签编号
getMaMachineLabelApi().then(response => {
this.labelCodeList = response.rows;
})
},
2023-12-19 04:26:18 +08:00
2024-03-07 11:38:10 +08:00
//选择设备类型
selectDevice(id){
console.log(id)
getListByMaType({typeId:id}).then(response => {
this.modelList = response.data;
}
);
},
2023-12-19 04:26:18 +08:00
2023-12-12 13:36:08 +08:00
/** 查询字典类型列表 */
getList() {
this.loading = true;
listLabelBind(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
2023-12-20 20:17:03 +08:00
this.labelList = response.rows;
this.total = response.total;
this.loading = false;
}
2023-12-12 13:36:08 +08:00
);
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
2023-12-19 04:26:18 +08:00
typeId: undefined,
maId: undefined,
labelType: undefined,
labelCode: undefined,
2023-12-12 13:36:08 +08:00
remark: undefined
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm("queryForm");
this.handleQuery();
},
2023-12-19 04:26:18 +08:00
/** 绑定按钮操作 */
handleBind() {
2023-12-12 13:36:08 +08:00
this.reset();
this.open = true;
this.title = "绑定";
2023-12-20 20:41:12 +08:00
this.form.id = this.ids[0].id;
2023-12-22 17:13:57 +08:00
// this.form.typeId = this.ids[0].typeId;
2023-12-19 04:26:18 +08:00
this.form.maId = this.ids[0].maId;
2023-12-22 14:05:57 +08:00
this.form.labelId = this.ids[0].labelId;
2023-12-20 20:17:03 +08:00
this.form.labelType = this.ids[0].labelType;
this.form.labelCode = this.ids[0].labelCode;
2023-12-22 17:13:57 +08:00
getDeviceTypeTree({ "level": "4" }).then(response => {
this.deptOptions = response.data;
});
2023-12-19 04:26:18 +08:00
},
2023-12-20 20:17:03 +08:00
/** 修改按钮操作 */
handleUpdate(row) {
2023-12-19 04:26:18 +08:00
// this.reset();
// const maId = row.maId || this.ids
// getType(maId).then(response => {
// this.form = response.data;
// this.open = true;
// this.title = "绑定";
// });
},
/** 提交按钮 */
2023-12-20 20:17:03 +08:00
submitForm: function () {
this.form.binder = this.userInfo.id + '';
2023-12-22 17:13:57 +08:00
// this.form.typeId
console.log(this.form);
2023-12-19 04:26:18 +08:00
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.level == '4') {
if (this.form.maCode.indexOf('null') > 0) {
2023-12-24 00:15:02 +08:00
this.$modal.msgError("请输入正确规则的设备编码!");
} else {
2023-12-24 00:15:02 +08:00
addLabelBind(this.form).then(response => {
this.$modal.msgSuccess("绑定成功");
this.open = false;
this.getList();
});
}
} else {
2023-12-24 00:15:02 +08:00
this.$modal.msgError("当前类型无法生成标签,请选择设备类型-规格型号!");
}
2023-12-24 00:15:02 +08:00
2023-12-19 04:26:18 +08:00
}
});
},
2023-12-24 00:15:02 +08:00
selectType(val) {
console.log(val)
if (!val.children) {
2023-12-24 00:15:02 +08:00
console.log(val)
2023-12-24 00:15:02 +08:00
let nTime = new Date();
let nYear = nTime.getFullYear() + '';
2023-12-24 00:15:02 +08:00
let nMonth = nTime.getMonth() + 1;
console.log(nYear)
console.log(nMonth)
this.form.level = '4';
2023-12-24 00:15:02 +08:00
// let arr = this.form.arrivalTime.split('-')
this.$set(this.form, 'maCode', 'NSJJ' + val.code + val.modelCode + nYear[2] + nYear[3] + nMonth)
} else {
this.form.level = '';
this.$set(this.form, 'maCode', '')
2023-12-24 00:15:02 +08:00
}
2023-12-22 17:13:57 +08:00
this.form.typeId = val.id
},
2023-12-19 04:26:18 +08:00
/** 删除按钮操作 */
handleDelete(row) {
2023-12-20 20:17:03 +08:00
const id = row.id;
this.$modal.confirm('是否确认解绑数据项?').then(function () {
return delLabelBind(id);
2023-12-19 04:26:18 +08:00
}).then(() => {
this.getList();
this.$modal.msgSuccess("解绑成功");
2023-12-20 20:17:03 +08:00
}).catch(() => { });
2023-12-12 13:36:08 +08:00
},
// 标签生成按钮
createLabel() {
this.resetCreate();
this.createOpen = true;
this.title = "标签生成";
},
// 表单重置
resetCreate() {
this.cform = {
labelType: undefined,
labelNum: undefined,
};
this.resetForm("cform");
},
cancelCreate() {
this.createOpen = false;
this.resetCreate();
},
// 标签生成提交
2023-12-20 20:17:03 +08:00
submitCreate() {
2023-12-12 13:36:08 +08:00
this.$refs["cform"].validate(valid => {
if (valid) {
2023-12-20 20:17:03 +08:00
let uuidList = []
for (let i = 0; i < this.cform.labelNum; i++) {
uuidList.push(uuidv4())
// 索引,数组下标
}
let parmas = {
2023-12-21 17:54:28 +08:00
uuidList: uuidList.join(','),
2023-12-20 20:17:03 +08:00
labelType: this.cform.labelType,
labelNum: this.cform.labelNum,
}
addMaMachineLabelApi(parmas).then(res => {
if (res.code == 200) {
this.$modal.msgSuccess(res.msg);
this.createOpen = false;
this.getList();
}
})
// updateType(this.form).then(response => {
// this.open = false;
// this.getList();
// });
} else {
return false
2023-12-12 13:36:08 +08:00
}
});
},
//标签下载
2023-12-20 20:17:03 +08:00
async labelUpload() {
2023-12-23 23:24:35 +08:00
console.log('checkboxModel', this.checkboxModel);
2023-12-20 20:17:03 +08:00
const msg = this.$modal.loading("批量生成中,请稍候...");
try {
let that = this;
let captureId = document.getElementsByClassName("captureId");
for (let i = 0; i < this.checkboxModel.length; i++) {
const element = this.checkboxModel[i];
captureId[i].innerHTML = "";
let shareContent = that.$refs["QrcodePage"][i],
width = shareContent.offsetWidth,
height = shareContent.offsetHeight;
new QRCode(captureId[i], {
2023-12-23 23:24:35 +08:00
width: width,
height: height,
text: element.maCode,
colorDark: "#000",
colorLight: "#fff"
2023-12-20 20:17:03 +08:00
});
let canvas = document.createElement("canvas"),
scale = 1;
canvas.width = width * scale;
canvas.height = height * scale;
canvas.style.width = (shareContent.clientWidth * scale) / 100 + "rem";
canvas.style.height = (shareContent.clientHeight * scale) / 100 + "rem";
canvas.getContext("2d").scale(scale, scale);
let opts = {
scale: scale,
canvas: canvas,
logging: false,
width: width,
height: height,
useCORS: true
};
await html2canvas(shareContent, opts)
.then(function (canvas) {
const qrContentImage = canvas.toDataURL("image/jpeg", 1.0);
if (i <= that.checkboxModel.length - 1) {
that.qrcodeArr.push({
url: qrContentImage,
2023-12-23 23:24:35 +08:00
name: element.labelCode
2023-12-20 20:17:03 +08:00
});
}
})
.catch(function (reason) {
console.log(reason);
2023-12-23 23:24:35 +08:00
that.getList();
that.$modal.closeLoading();
2023-12-20 20:17:03 +08:00
});
}
2023-12-23 23:24:35 +08:00
await new Promise(resolve => setTimeout(resolve, 1000));
that.packageImages();
setTimeout(msg, 1000);
that.$modal.closeLoading();
2023-12-20 20:17:03 +08:00
} catch (error) {
setTimeout(msg, 1000);
2023-12-23 23:24:35 +08:00
that.getList();
that.$modal.closeLoading();
2023-12-20 20:17:03 +08:00
}
},
packageImages() {
let that = this;
const zip = new JSZip();
const cache = {};
2023-12-23 23:24:35 +08:00
let arr = that.qrcodeArr;
arr.forEach((item, index) => {
let fileName = item.name;
zip.file(fileName + ".png", item.url.substring(22), { base64: true });
cache[fileName] = item.url;
});
zip.generateAsync({ type: "blob" }).then(content => {
FileSaver.saveAs(content, "二维码.zip");
});
that.getList();
that.qrcodeArr = [];
2023-12-20 20:17:03 +08:00
},
2023-12-23 23:24:35 +08:00
2023-12-20 20:17:03 +08:00
labelUploadCode(row) {
2023-12-23 23:24:35 +08:00
// if (row.maCode == null) {
// this.$message.error('当前设备没有设备编码');
// return
// }
2023-12-22 14:05:57 +08:00
this.labelCodeName = ''
2023-12-20 20:17:03 +08:00
this.rowObj = row
2023-12-12 13:36:08 +08:00
this.uploadOpen = true;
this.title = "二维码查看";
2023-12-23 23:24:35 +08:00
this.labelmaCode = row.labelCode
2024-03-05 09:10:14 +08:00
let str = 'http://112.29.103.165:21624/qrCode/qrCodePage?qrCode='+row.labelCode
2023-12-20 20:17:03 +08:00
this.$nextTick(() => {
// this.selectionList.forEach((item, index) => {
this.$refs.codeItem.innerHTML = "";
var qrcode = new QRCode(this.$refs.codeItem, {
text: str, //二维码内容
2023-12-20 20:17:03 +08:00
width: 256,
height: 256,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H,
})
// });
}, 500)
},
downloadCode(e) {
let imgSrc, canvas
if (document.getElementById('qrcode').childNodes[0]) {
canvas = document.getElementById('qrcode').childNodes[0]
imgSrc = this.CanvasToImage(canvas).getAttribute('src')
const alink = document.createElement('a')
alink.href = imgSrc
2023-12-22 14:05:57 +08:00
alink.download = this.labelmaCode
2023-12-20 20:17:03 +08:00
alink.click()
}
},
CanvasToImage(canvas) {
// 新Image对象可以理解为DOM
var image = new Image()
// canvas.toDataURL 返回的是一串Base64编码的URL当然,浏览器自己肯定支持
// 指定格式PNG
image.src = canvas.toDataURL('image/png')
return image
2023-12-12 13:36:08 +08:00
},
2023-12-20 20:17:03 +08:00
// 分享二维码弹窗
popQrcode() {
this.qrcodeDialogVisible = true
const colorFore = '#4169E1'
const colorOut = '#CD5C5C'
const colorIn = '#191970'
this.qrcode = ''
this.$nextTick(() => {
this.qrcode = qrcanvas({
cellSize: 8,
data: location.href,
effect: { round: 0.4 },
correctLevel: 'M',
foreground: [
// 前景色
{ style: colorFore },
// 外方块位置
{ row: 0, rows: 7, col: 0, cols: 7, style: colorOut },
{ row: -7, rows: 7, col: 0, cols: 7, style: colorOut },
{ row: 0, rows: 7, col: -7, cols: 7, style: colorOut },
// 内方块位置
{ row: 2, rows: 3, col: 2, cols: 3, style: colorIn },
{ row: -5, rows: 3, col: 2, cols: 3, style: colorIn },
{ row: 2, rows: 3, col: -5, cols: 3, style: colorIn }
],
background: '#f5f5f5',
padding: 12
})
// 判断是否有子节点,如果已经有则删除原有的,然后再新增子节点
if (document.getElementById('qrcode').childNodes[0]) {
this.$refs.qrcode.removeChild(document.getElementById('qrcode').childNodes[0])
}
this.$refs.qrcode.appendChild(this.qrcode)
})
},
// downloadCode() { },
2023-12-12 13:36:08 +08:00
// 多选框选中数据
handleSelectionChange(selection) {
2023-12-20 20:17:03 +08:00
console.log('thhis,', selection);
this.selectionList = selection
this.checkboxModel = selection
2023-12-19 04:26:18 +08:00
this.ids = selection.map(item => item)
2023-12-20 20:17:03 +08:00
this.single = selection.length != 1
2023-12-12 13:36:08 +08:00
this.multiple = !selection.length
},
2023-12-20 20:17:03 +08:00
2023-12-12 13:36:08 +08:00
/** 导出按钮操作 */
handleExport() {
this.download('system/dict/type/export', {
...this.queryParams
}, `type_${new Date().getTime()}.xlsx`)
},
/** 刷新缓存按钮操作 */
handleRefreshCache() {
refreshCache().then(() => {
this.$modal.msgSuccess("刷新成功");
this.$store.dispatch('dict/cleanDict');
});
}
}
};
</script>
2024-01-12 10:07:35 +08:00
<style lang="scss" scoped>
2023-12-20 20:17:03 +08:00
.uploadImg {
display: flex;
align-items: center;
justify-content: center;
}
.maCode {
margin-top: 15px;
font-size: 18px;
2023-12-12 13:36:08 +08:00
}
2024-01-12 10:07:35 +08:00
::v-deep.el-table .fixed-width .el-button--mini {
width: 60px !important;
margin-bottom: 10px;
}
2024-03-05 18:41:35 +08:00
</style>