|
@@ -25,7 +25,7 @@
|
|
</my-modal>
|
|
</my-modal>
|
|
</template>
|
|
</template>
|
|
<script name="ImportCardDialog" lang="ts" setup>
|
|
<script name="ImportCardDialog" lang="ts" setup>
|
|
-import { ref, reactive } from "vue";
|
|
|
|
|
|
+import { ref, reactive, computed } from "vue";
|
|
import { importCard } from "@/ap/baseDataConfig";
|
|
import { importCard } from "@/ap/baseDataConfig";
|
|
import { useUserStore } from "@/store";
|
|
import { useUserStore } from "@/store";
|
|
import SelectSubject from "@/components/SelectSubject/index.vue";
|
|
import SelectSubject from "@/components/SelectSubject/index.vue";
|
|
@@ -40,39 +40,152 @@ const params = reactive({
|
|
file: null,
|
|
file: null,
|
|
paperCount: void 0,
|
|
paperCount: void 0,
|
|
singlePage: false,
|
|
singlePage: false,
|
|
|
|
+ // dpi: 150,
|
|
});
|
|
});
|
|
-const fields = ref([
|
|
|
|
- { prop: "subjectCode", cell: "subjectCode", label: "科目题卡", colSpan: 24 },
|
|
|
|
- { prop: "remark", type: "textarea", label: "备注", colSpan: 24 },
|
|
|
|
- { prop: "file", cell: "file", label: "选择卡格式", colSpan: 24 },
|
|
|
|
- {
|
|
|
|
- prop: "paperCount",
|
|
|
|
- type: "number",
|
|
|
|
- label: "张数",
|
|
|
|
- colSpan: 24,
|
|
|
|
- attrs: { min: 1 },
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- prop: "singlePage",
|
|
|
|
- type: "radio",
|
|
|
|
- label: "单页题卡",
|
|
|
|
- colSpan: 24,
|
|
|
|
- attrs: {
|
|
|
|
- options: [
|
|
|
|
- { value: false, label: "否" },
|
|
|
|
- { value: true, label: "是" },
|
|
|
|
- ],
|
|
|
|
|
|
+const cardJson = ref(null);
|
|
|
|
+const fields = computed(() => {
|
|
|
|
+ return [
|
|
|
|
+ {
|
|
|
|
+ prop: "subjectCode",
|
|
|
|
+ cell: "subjectCode",
|
|
|
|
+ label: "科目题卡",
|
|
|
|
+ colSpan: 24,
|
|
},
|
|
},
|
|
- },
|
|
|
|
-]);
|
|
|
|
|
|
+ { prop: "remark", type: "textarea", label: "备注", colSpan: 24 },
|
|
|
|
+ { prop: "file", cell: "file", label: "选择卡格式", colSpan: 24 },
|
|
|
|
+ {
|
|
|
|
+ prop: "paperCount",
|
|
|
|
+ type: "number",
|
|
|
|
+ label: "张数",
|
|
|
|
+ colSpan: 24,
|
|
|
|
+ attrs: { min: 1 },
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ prop: "singlePage",
|
|
|
|
+ type: "radio",
|
|
|
|
+ label: "单页题卡",
|
|
|
|
+ colSpan: 24,
|
|
|
|
+ attrs: {
|
|
|
|
+ options: [
|
|
|
|
+ { value: false, label: "否" },
|
|
|
|
+ { value: true, label: "是" },
|
|
|
|
+ ],
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ // params.file && isJson.value && cardJson.value && !cardJson.value.dpi
|
|
|
|
+ // ? {
|
|
|
|
+ // prop: "dpi",
|
|
|
|
+ // type: "radio",
|
|
|
|
+ // label: "DPI",
|
|
|
|
+ // colSpan: 24,
|
|
|
|
+ // attrs: {
|
|
|
|
+ // options: [
|
|
|
|
+ // { value: 150, label: "150" },
|
|
|
|
+ // { value: 200, label: "200" },
|
|
|
|
+ // ],
|
|
|
|
+ // disabled: cardJson.value?.dpi,
|
|
|
|
+ // },
|
|
|
|
+ // }
|
|
|
|
+ // : null,
|
|
|
|
+ ];
|
|
|
|
+});
|
|
|
|
+const isJson = ref(true);
|
|
|
|
+const cardSizePass = ref(true);
|
|
|
|
+
|
|
|
|
+const isJsonString = (str) => {
|
|
|
|
+ try {
|
|
|
|
+ const toObj = JSON.parse(str);
|
|
|
|
+ if (toObj && typeof toObj === "object") {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ } catch {}
|
|
|
|
+ return false;
|
|
|
|
+};
|
|
|
|
|
|
const rules = {
|
|
const rules = {
|
|
subjectCode: [{ required: true, message: "请选择科目" }],
|
|
subjectCode: [{ required: true, message: "请选择科目" }],
|
|
- file: [{ required: true, message: "请上传文件" }],
|
|
|
|
- paperCount: [{ required: true, message: "请输入张数" }],
|
|
|
|
|
|
+ file: [
|
|
|
|
+ { required: true, message: "请上传文件" },
|
|
|
|
+ {
|
|
|
|
+ validator: async () => {
|
|
|
|
+ if (!isJson) {
|
|
|
|
+ return Promise.reject("卡格式json文件内容异常,请检查");
|
|
|
|
+ } else {
|
|
|
|
+ if (cardJson.value && !cardSizePass.value) {
|
|
|
|
+ return Promise.reject("卡格式图片dpi异常!");
|
|
|
|
+ } else {
|
|
|
|
+ return Promise.resolve();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ paperCount: [
|
|
|
|
+ { required: true, message: "请输入张数" },
|
|
|
|
+ {
|
|
|
|
+ validator: async (rule: any, value: any) => {
|
|
|
|
+ if (cardJson.value) {
|
|
|
|
+ if (
|
|
|
|
+ (params.singlePage && cardJson.value.pages.length != value) ||
|
|
|
|
+ (!params.singlePage && cardJson.value.pages.length / 2 != value)
|
|
|
|
+ ) {
|
|
|
|
+ return Promise.reject("张数未校验通过,请检查!");
|
|
|
|
+ } else {
|
|
|
|
+ return Promise.resolve();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ return Promise.resolve();
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+};
|
|
|
|
+const compareSize = (content: any, img: any) => {
|
|
|
|
+ console.log(content, img.width, img.height);
|
|
|
|
+};
|
|
|
|
+const validateCardSize = async (json) => {
|
|
|
|
+ if (!json.pages.length) {
|
|
|
|
+ cardSizePass.value = false;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ window.electronApi?.getPageSizeIni((content: any) => {
|
|
|
|
+ console.log(content);
|
|
|
|
+ const img = new Image();
|
|
|
|
+ img.onload = () => {
|
|
|
|
+ compareSize(content, img);
|
|
|
|
+ };
|
|
|
|
+ img.onerror = function () {
|
|
|
|
+ window.$message.error("卡格式json文件里的图片base64无效!");
|
|
|
|
+ };
|
|
|
|
+ img.src = "data:image/jpg;base64," + json.pages[0].exchange["page_image"];
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+const getCardJsonContent = async (file: any) => {
|
|
|
|
+ const reader = new FileReader();
|
|
|
|
+ reader.onload = function (e) {
|
|
|
|
+ try {
|
|
|
|
+ const json = JSON.parse(e.target.result);
|
|
|
|
+ console.log("json", json);
|
|
|
|
+ cardJson.value = json;
|
|
|
|
+ if (json.dpi) {
|
|
|
|
+ params.dpi = Number(json.dpi);
|
|
|
|
+ }
|
|
|
|
+ validateCardSize(json);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error("Error parsing JSON:", error);
|
|
|
|
+ isJson.value = false;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ reader.onerror = function (error) {
|
|
|
|
+ console.error("File could not be read:", error);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ reader.readAsText(file);
|
|
};
|
|
};
|
|
const getFile = (file: any) => {
|
|
const getFile = (file: any) => {
|
|
params.file = file;
|
|
params.file = file;
|
|
|
|
+ getCardJsonContent(file);
|
|
};
|
|
};
|
|
const submitHandle = () => {
|
|
const submitHandle = () => {
|
|
form.value.formRef.validate().then(() => {
|
|
form.value.formRef.validate().then(() => {
|