|
@@ -98,7 +98,6 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
-import { deepCopy } from "@/plugins/utils";
|
|
|
|
import { schoolSetStdnoInfo, schoolSetStdnoUpdate } from "../../api";
|
|
import { schoolSetStdnoInfo, schoolSetStdnoUpdate } from "../../api";
|
|
import HeadStdno from "../../../../../card/elements/card-head/cardHeadSpin/HeadStdno.vue";
|
|
import HeadStdno from "../../../../../card/elements/card-head/cardHeadSpin/HeadStdno.vue";
|
|
|
|
|
|
@@ -124,6 +123,7 @@ export default {
|
|
relationList: [],
|
|
relationList: [],
|
|
columnChar: "",
|
|
columnChar: "",
|
|
},
|
|
},
|
|
|
|
+ cachedModalForm: null,
|
|
curSelectColumn: -1,
|
|
curSelectColumn: -1,
|
|
curSelectColumnLetters: [],
|
|
curSelectColumnLetters: [],
|
|
rules: {
|
|
rules: {
|
|
@@ -141,7 +141,6 @@ export default {
|
|
if (!value || !value.length) {
|
|
if (!value || !value.length) {
|
|
return callback(new Error(`请选择字母所在列`));
|
|
return callback(new Error(`请选择字母所在列`));
|
|
}
|
|
}
|
|
-
|
|
|
|
callback();
|
|
callback();
|
|
},
|
|
},
|
|
trigger: "change",
|
|
trigger: "change",
|
|
@@ -151,17 +150,15 @@ export default {
|
|
{
|
|
{
|
|
required: true,
|
|
required: true,
|
|
validator: (rule, value, callback) => {
|
|
validator: (rule, value, callback) => {
|
|
- if (!/^[A-Z]{1,10}$/.test(value)) {
|
|
|
|
- return callback(new Error(`只能输入大写字母,长度不超过10`));
|
|
|
|
|
|
+ if (!value) {
|
|
|
|
+ return callback(new Error(`请输入使用字母`));
|
|
}
|
|
}
|
|
-
|
|
|
|
- const chars = Array.from(new Set((value || "").split(""))).join(
|
|
|
|
- ""
|
|
|
|
- );
|
|
|
|
- if (chars !== value) {
|
|
|
|
- return callback(new Error(`大写字母不可重复`));
|
|
|
|
|
|
+ if (!/^[A-Z]+$/.test(value)) {
|
|
|
|
+ return callback(new Error(`请输入大写字母`));
|
|
|
|
+ }
|
|
|
|
+ if (value.length > 10) {
|
|
|
|
+ return callback(new Error(`最多输入10个字母`));
|
|
}
|
|
}
|
|
-
|
|
|
|
callback();
|
|
callback();
|
|
},
|
|
},
|
|
trigger: "change",
|
|
trigger: "change",
|
|
@@ -170,14 +167,13 @@ export default {
|
|
},
|
|
},
|
|
};
|
|
};
|
|
},
|
|
},
|
|
- computed: {
|
|
|
|
- headStdnoData() {
|
|
|
|
- return {
|
|
|
|
- examNumberStyle: "FILL",
|
|
|
|
- fillNumber: this.modalForm.digit,
|
|
|
|
- containsLetter: this.modalForm.containsLetter,
|
|
|
|
- relationList: this.modalForm.relationList,
|
|
|
|
- };
|
|
|
|
|
|
+ watch: {
|
|
|
|
+ modalForm: {
|
|
|
|
+ deep: true,
|
|
|
|
+ handler() {
|
|
|
|
+ const isChanged = this.checkConfigChanged();
|
|
|
|
+ this.$emit("config-changed", isChanged);
|
|
|
|
+ },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
@@ -186,125 +182,65 @@ export default {
|
|
methods: {
|
|
methods: {
|
|
async initData() {
|
|
async initData() {
|
|
const data = await schoolSetStdnoInfo(this.school.id);
|
|
const data = await schoolSetStdnoInfo(this.school.id);
|
|
- this.stdnoInfo = data.result;
|
|
|
|
- const config = data.result[0].value;
|
|
|
|
- if (!config) {
|
|
|
|
- this.modalForm = {
|
|
|
|
- digit: 10,
|
|
|
|
- containsLetter: false,
|
|
|
|
- columns: [],
|
|
|
|
- relationList: [],
|
|
|
|
- columnChar: "",
|
|
|
|
- };
|
|
|
|
- return;
|
|
|
|
|
|
+ if (data && data.result) {
|
|
|
|
+ this.modalForm = data.result;
|
|
}
|
|
}
|
|
-
|
|
|
|
- this.modalForm = {
|
|
|
|
- digit: config.digit || 10,
|
|
|
|
- containsLetter: config.containsLetter,
|
|
|
|
- columns: [],
|
|
|
|
- relationList: config.relationList || [],
|
|
|
|
- columnChar: "",
|
|
|
|
- };
|
|
|
|
- this.modalForm.columns = this.modalForm.relationList.map(
|
|
|
|
- (item) => item.columnIndex
|
|
|
|
|
|
+ this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
|
|
|
|
+ },
|
|
|
|
+ checkConfigChanged() {
|
|
|
|
+ if (!this.cachedModalForm) return false;
|
|
|
|
+ return (
|
|
|
|
+ JSON.stringify(this.modalForm) !== JSON.stringify(this.cachedModalForm)
|
|
);
|
|
);
|
|
- if (this.modalForm.columns.length) {
|
|
|
|
- this.curSelectColumn = this.modalForm.columns[0];
|
|
|
|
- this.selectColumnChange();
|
|
|
|
- }
|
|
|
|
},
|
|
},
|
|
- toSwitchColumn(val) {
|
|
|
|
- this.curSelectColumn = val.columnIndex;
|
|
|
|
|
|
+ columnChange(val) {
|
|
|
|
+ this.modalForm.relationList = val.map((item) => ({
|
|
|
|
+ columnIndex: item,
|
|
|
|
+ letters: [],
|
|
|
|
+ }));
|
|
|
|
+ this.curSelectColumn = val[0] || -1;
|
|
|
|
+ this.curSelectColumnLetters = [];
|
|
|
|
+ this.modalForm.columnChar = "";
|
|
},
|
|
},
|
|
- columnChange() {
|
|
|
|
- const relationList = this.modalForm.relationList || [];
|
|
|
|
- const relationMap = {};
|
|
|
|
- relationList.forEach((item) => {
|
|
|
|
- relationMap[item.columnIndex] = item.letters;
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- this.modalForm.columns.sort((a, b) => a - b);
|
|
|
|
-
|
|
|
|
- this.modalForm.relationList = this.modalForm.columns.map(
|
|
|
|
- (columnIndex) => {
|
|
|
|
- const letters = relationMap[columnIndex] || [];
|
|
|
|
- return {
|
|
|
|
- columnIndex,
|
|
|
|
- letters,
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
|
|
+ selectColumnChange(val) {
|
|
|
|
+ this.curSelectColumn = val;
|
|
|
|
+ const relation = this.modalForm.relationList.find(
|
|
|
|
+ (item) => item.columnIndex === val
|
|
);
|
|
);
|
|
-
|
|
|
|
- if (
|
|
|
|
- this.modalForm.columns.length &&
|
|
|
|
- !this.modalForm.columns.includes(this.curSelectColumn)
|
|
|
|
- ) {
|
|
|
|
- this.curSelectColumn = this.modalForm.columns[0];
|
|
|
|
- this.selectColumnChange();
|
|
|
|
- }
|
|
|
|
|
|
+ this.curSelectColumnLetters = relation ? relation.letters : [];
|
|
|
|
+ this.modalForm.columnChar = this.curSelectColumnLetters.join("");
|
|
},
|
|
},
|
|
- selectColumnChange() {
|
|
|
|
- const curRelation = this.modalForm.relationList.find(
|
|
|
|
|
|
+ columnCharChange(val) {
|
|
|
|
+ if (!val) return;
|
|
|
|
+ const letters = val.split("");
|
|
|
|
+ const relation = this.modalForm.relationList.find(
|
|
(item) => item.columnIndex === this.curSelectColumn
|
|
(item) => item.columnIndex === this.curSelectColumn
|
|
);
|
|
);
|
|
- this.modalForm.columnChar = curRelation
|
|
|
|
- ? curRelation.letters.join("")
|
|
|
|
- : "";
|
|
|
|
- this.curSelectColumnLetters = curRelation ? curRelation.letters : [];
|
|
|
|
- },
|
|
|
|
- validateField(field) {
|
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
- this.$refs.modalFormComp.validateField(field, (unvalid) => {
|
|
|
|
- if (unvalid) {
|
|
|
|
- reject(false);
|
|
|
|
- } else {
|
|
|
|
- resolve(true);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
- async columnCharChange() {
|
|
|
|
- const res = await this.validateField("columnChar").catch(() => {});
|
|
|
|
- if (!res) {
|
|
|
|
- this.curSelectColumnLetters = [];
|
|
|
|
- return;
|
|
|
|
|
|
+ if (relation) {
|
|
|
|
+ relation.letters = letters;
|
|
}
|
|
}
|
|
-
|
|
|
|
- const curRelation = this.modalForm.relationList.find(
|
|
|
|
- (item) => item.columnIndex === this.curSelectColumn
|
|
|
|
- );
|
|
|
|
- if (!curRelation) return;
|
|
|
|
- curRelation.letters = this.modalForm.columnChar.split("");
|
|
|
|
- this.curSelectColumnLetters = curRelation.letters;
|
|
|
|
|
|
+ this.curSelectColumnLetters = letters;
|
|
},
|
|
},
|
|
async confirm() {
|
|
async confirm() {
|
|
- const valid = await this.$refs.modalFormComp.validate().catch(() => {});
|
|
|
|
|
|
+ const valid = await this.$refs.modalFormComp.validate();
|
|
if (!valid) return;
|
|
if (!valid) return;
|
|
|
|
|
|
if (this.loading) return;
|
|
if (this.loading) return;
|
|
this.loading = true;
|
|
this.loading = true;
|
|
|
|
|
|
- const val = {
|
|
|
|
- digit: this.modalForm.digit,
|
|
|
|
- containsLetter: this.modalForm.containsLetter,
|
|
|
|
- relationList: this.modalForm.containsLetter
|
|
|
|
- ? this.modalForm.relationList
|
|
|
|
- : [],
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- const datas = deepCopy(this.stdnoInfo);
|
|
|
|
- datas[0].value = val;
|
|
|
|
- const res = await schoolSetStdnoUpdate({
|
|
|
|
- param: datas,
|
|
|
|
- schoolId: this.school.id,
|
|
|
|
- }).catch(() => {});
|
|
|
|
- this.loading = false;
|
|
|
|
-
|
|
|
|
- if (!res) return;
|
|
|
|
-
|
|
|
|
- this.$message.success("修改成功!");
|
|
|
|
- this.initData();
|
|
|
|
|
|
+ try {
|
|
|
|
+ await schoolSetStdnoUpdate({
|
|
|
|
+ ...this.modalForm,
|
|
|
|
+ schoolId: this.school.id,
|
|
|
|
+ });
|
|
|
|
+ this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
|
|
|
|
+ this.$emit("config-changed", false);
|
|
|
|
+ this.$message.success("修改成功!");
|
|
|
|
+ } catch (error) {
|
|
|
|
+ this.$message.error(error.message || "保存失败");
|
|
|
|
+ } finally {
|
|
|
|
+ this.loading = false;
|
|
|
|
+ }
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
};
|