|
@@ -82,11 +82,6 @@
|
|
|
</el-form-item>
|
|
|
</template>
|
|
|
</template>
|
|
|
- <el-form-item>
|
|
|
- <el-button type="primary" :loading="loading" @click="confirm"
|
|
|
- >保存</el-button
|
|
|
- >
|
|
|
- </el-form-item>
|
|
|
</el-form>
|
|
|
|
|
|
<!-- stdno view -->
|
|
@@ -98,6 +93,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { deepCopy } from "@/plugins/utils";
|
|
|
import { schoolSetStdnoInfo, schoolSetStdnoUpdate } from "../../api";
|
|
|
import HeadStdno from "../../../../../card/elements/card-head/cardHeadSpin/HeadStdno.vue";
|
|
|
|
|
@@ -150,15 +146,17 @@ export default {
|
|
|
{
|
|
|
required: true,
|
|
|
validator: (rule, value, callback) => {
|
|
|
- if (!value) {
|
|
|
- return callback(new Error(`请输入使用字母`));
|
|
|
- }
|
|
|
- if (!/^[A-Z]+$/.test(value)) {
|
|
|
- return callback(new Error(`请输入大写字母`));
|
|
|
+ if (!/^[A-Z]{1,10}$/.test(value)) {
|
|
|
+ return callback(new Error(`只能输入大写字母,长度不超过10`));
|
|
|
}
|
|
|
- if (value.length > 10) {
|
|
|
- return callback(new Error(`最多输入10个字母`));
|
|
|
+
|
|
|
+ const chars = Array.from(new Set((value || "").split(""))).join(
|
|
|
+ ""
|
|
|
+ );
|
|
|
+ if (chars !== value) {
|
|
|
+ return callback(new Error(`大写字母不可重复`));
|
|
|
}
|
|
|
+
|
|
|
callback();
|
|
|
},
|
|
|
trigger: "change",
|
|
@@ -167,6 +165,16 @@ export default {
|
|
|
},
|
|
|
};
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ headStdnoData() {
|
|
|
+ return {
|
|
|
+ examNumberStyle: "FILL",
|
|
|
+ fillNumber: this.modalForm.digit,
|
|
|
+ containsLetter: this.modalForm.containsLetter,
|
|
|
+ relationList: this.modalForm.relationList,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ },
|
|
|
watch: {
|
|
|
modalForm: {
|
|
|
deep: true,
|
|
@@ -182,9 +190,37 @@ export default {
|
|
|
methods: {
|
|
|
async initData() {
|
|
|
const data = await schoolSetStdnoInfo(this.school.id);
|
|
|
- if (data && data.result) {
|
|
|
- this.modalForm = data.result;
|
|
|
+ const config = data.result[0].value;
|
|
|
+ if (!config) {
|
|
|
+ this.modalForm = {
|
|
|
+ digit: 10,
|
|
|
+ containsLetter: false,
|
|
|
+ columns: [],
|
|
|
+ relationList: [],
|
|
|
+ columnChar: "",
|
|
|
+ };
|
|
|
+ this.updateCachedModalForm();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.modalForm = {
|
|
|
+ digit: config.digit || 10,
|
|
|
+ containsLetter: config.containsLetter,
|
|
|
+ columns: [],
|
|
|
+ relationList: config.relationList || [],
|
|
|
+ columnChar: "",
|
|
|
+ };
|
|
|
+ this.modalForm.columns = this.modalForm.relationList.map(
|
|
|
+ (item) => item.columnIndex
|
|
|
+ );
|
|
|
+ if (this.modalForm.columns.length) {
|
|
|
+ this.curSelectColumn = this.modalForm.columns[0];
|
|
|
+ this.selectColumnChange();
|
|
|
}
|
|
|
+
|
|
|
+ this.updateCachedModalForm();
|
|
|
+ },
|
|
|
+ updateCachedModalForm() {
|
|
|
this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
|
|
|
},
|
|
|
checkConfigChanged() {
|
|
@@ -193,54 +229,94 @@ export default {
|
|
|
JSON.stringify(this.modalForm) !== JSON.stringify(this.cachedModalForm)
|
|
|
);
|
|
|
},
|
|
|
- columnChange(val) {
|
|
|
- this.modalForm.relationList = val.map((item) => ({
|
|
|
- columnIndex: item,
|
|
|
- letters: [],
|
|
|
- }));
|
|
|
- this.curSelectColumn = val[0] || -1;
|
|
|
- this.curSelectColumnLetters = [];
|
|
|
- this.modalForm.columnChar = "";
|
|
|
- },
|
|
|
- selectColumnChange(val) {
|
|
|
- this.curSelectColumn = val;
|
|
|
- const relation = this.modalForm.relationList.find(
|
|
|
- (item) => item.columnIndex === val
|
|
|
+ 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,
|
|
|
+ };
|
|
|
+ }
|
|
|
);
|
|
|
- this.curSelectColumnLetters = relation ? relation.letters : [];
|
|
|
- this.modalForm.columnChar = this.curSelectColumnLetters.join("");
|
|
|
+
|
|
|
+ if (
|
|
|
+ this.modalForm.columns.length &&
|
|
|
+ !this.modalForm.columns.includes(this.curSelectColumn)
|
|
|
+ ) {
|
|
|
+ this.curSelectColumn = this.modalForm.columns[0];
|
|
|
+ this.selectColumnChange();
|
|
|
+ }
|
|
|
},
|
|
|
- columnCharChange(val) {
|
|
|
- if (!val) return;
|
|
|
- const letters = val.split("");
|
|
|
- const relation = this.modalForm.relationList.find(
|
|
|
+ selectColumnChange() {
|
|
|
+ const curRelation = this.modalForm.relationList.find(
|
|
|
(item) => item.columnIndex === this.curSelectColumn
|
|
|
);
|
|
|
- if (relation) {
|
|
|
- relation.letters = letters;
|
|
|
+ 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;
|
|
|
}
|
|
|
- this.curSelectColumnLetters = 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;
|
|
|
},
|
|
|
async confirm() {
|
|
|
- const valid = await this.$refs.modalFormComp.validate();
|
|
|
+ const valid = await this.$refs.modalFormComp.validate().catch(() => {});
|
|
|
if (!valid) return;
|
|
|
|
|
|
if (this.loading) return;
|
|
|
this.loading = true;
|
|
|
|
|
|
- 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;
|
|
|
- }
|
|
|
+ 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.updateCachedModalForm();
|
|
|
+ this.$emit("config-changed", false);
|
|
|
+ this.initData();
|
|
|
},
|
|
|
},
|
|
|
};
|