Преглед на файлове

优化导入学生id和座号检查逻辑

liqk преди 4 години
родител
ревизия
9cfda534b1

+ 1 - 0
TEAMModelOS/ClientApp/src/locale/lang/en-US/stuAccount.js

@@ -94,6 +94,7 @@ export default {
   attrWarning:'警告:Excel 內栏位不完整!',
   attrWarning:'警告:Excel 內栏位不完整!',
   setNoWarning:'警告:Excel 內的座位号重覆!',
   setNoWarning:'警告:Excel 內的座位号重覆!',
   idWarning:'警告:Excel 內账号重复!',
   idWarning:'警告:Excel 內账号重复!',
+  idFormatWarning:'错误:学生账号只能包含数字',
   gradeWarning:'警告:年级错误',
   gradeWarning:'警告:年级错误',
   setNoErr:"错误:座位号已在校內重复",
   setNoErr:"错误:座位号已在校內重复",
   downloadText:'(下載名單模板)',
   downloadText:'(下載名單模板)',

+ 1 - 0
TEAMModelOS/ClientApp/src/locale/lang/zh-CN/stuAccount.js

@@ -94,6 +94,7 @@ export default {
   attrWarning:'警告:Excel 內栏位不完整!',
   attrWarning:'警告:Excel 內栏位不完整!',
   setNoWarning:'警告:Excel 內的座位号重覆!',
   setNoWarning:'警告:Excel 內的座位号重覆!',
   idWarning:'警告:Excel 內账号重复!',
   idWarning:'警告:Excel 內账号重复!',
+  idFormatWarning:'错误:学生账号只能包含数字',
   gradeWarning:'警告:年级错误',
   gradeWarning:'警告:年级错误',
   setNoErr:"错误:座位号已在校內重复",
   setNoErr:"错误:座位号已在校內重复",
   downloadText:'(下载名单模板)',
   downloadText:'(下载名单模板)',

+ 2 - 1
TEAMModelOS/ClientApp/src/locale/lang/zh-TW/stuAccount.js

@@ -3,7 +3,7 @@ export default {
   seatNo: '座號',
   seatNo: '座號',
   account: '帳號資訊',
   account: '帳號資訊',
   stuName: '姓名',
   stuName: '姓名',
-  classroomCode: '教室編碼',
+  classroomCode: '班級',
   classroomName: '教室名稱',
   classroomName: '教室名稱',
   period: '學制',
   period: '學制',
   grade: '年級',
   grade: '年級',
@@ -94,6 +94,7 @@ export default {
   attrWarning:'警告:Excel 內欄位不完整! ',
   attrWarning:'警告:Excel 內欄位不完整! ',
   setNoWarning:'警告:Excel 內的座號重覆! ',
   setNoWarning:'警告:Excel 內的座號重覆! ',
   idWarning:'警告:Excel 內帳號重複! ',
   idWarning:'警告:Excel 內帳號重複! ',
+  idFormatWarning:'錯誤:學生賬號只能包含數字',
   gradeWarning:'警告:年級錯誤',
   gradeWarning:'警告:年級錯誤',
   setNoErr:"錯誤:座位號已在校內重複",
   setNoErr:"錯誤:座位號已在校內重複",
   downloadText:'(下載名單模板)',
   downloadText:'(下載名單模板)',

+ 44 - 24
TEAMModelOS/ClientApp/src/view/student-account/ImportStudent.vue

@@ -76,6 +76,7 @@
                     <p :class="(excelValid.reaptIds.length == 0 || excelValid.reaptIds.indexOf(row.id) == -1) ? 'account-success-tips':'account-warning-tips'">{{(excelValid.reaptIds.length == 0 || excelValid.reaptIds.indexOf(row.id) == -1)?"": $t('stuAccount.idWarning') }}</p>
                     <p :class="(excelValid.reaptIds.length == 0 || excelValid.reaptIds.indexOf(row.id) == -1) ? 'account-success-tips':'account-warning-tips'">{{(excelValid.reaptIds.length == 0 || excelValid.reaptIds.indexOf(row.id) == -1)?"": $t('stuAccount.idWarning') }}</p>
                     <p :class="row.seatRepeat? 'account-error-tips':''">{{row.seatRepeat ? $t('stuAccount.setNoErr'):"" }}</p>
                     <p :class="row.seatRepeat? 'account-error-tips':''">{{row.seatRepeat ? $t('stuAccount.setNoErr'):"" }}</p>
                     <p :class="(excelValid.gradeIds.length == 0 || excelValid.gradeIds.indexOf(row.id) == -1) ? 'account-success-tips':'account-warning-tips'">{{(excelValid.gradeIds.length == 0 || excelValid.gradeIds.indexOf(row.id) == -1)?"": $t('stuAccount.gradeWarning') }}</p>
                     <p :class="(excelValid.gradeIds.length == 0 || excelValid.gradeIds.indexOf(row.id) == -1) ? 'account-success-tips':'account-warning-tips'">{{(excelValid.gradeIds.length == 0 || excelValid.gradeIds.indexOf(row.id) == -1)?"": $t('stuAccount.gradeWarning') }}</p>
+                    <p :class="(excelValid.idErr.length == 0 || !excelValid.idErr.includes(row.id)) ? 'account-success-tips':'account-error-tips'">{{(excelValid.idErr.length == 0 || !excelValid.idErr.includes(row.id))?"": $t('stuAccount.idFormatWarning') }}</p>
 
 
                 </template>
                 </template>
             </Table>
             </Table>
@@ -113,7 +114,8 @@ export default {
                 fieldIds: [],
                 fieldIds: [],
                 noReaptIds: [],
                 noReaptIds: [],
                 reaptIds: [],
                 reaptIds: [],
-                gradeIds: []
+                gradeIds: [],
+                idErr: [] //id格式不对
             },
             },
             totalNum: 0,
             totalNum: 0,
             seatRepeatNum: 0,
             seatRepeatNum: 0,
@@ -175,11 +177,10 @@ export default {
         },
         },
         rowClassName(row, index) {
         rowClassName(row, index) {
             let className = ''
             let className = ''
-
             if (this.excelValid.fieldIds.indexOf(row.id) >= 0 || this.excelValid.noReaptIds.indexOf(row.id) >= 0 || this.excelValid.reaptIds.indexOf(row.id) >= 0 || this.excelValid.gradeIds.indexOf(row.id) >= 0) {
             if (this.excelValid.fieldIds.indexOf(row.id) >= 0 || this.excelValid.noReaptIds.indexOf(row.id) >= 0 || this.excelValid.reaptIds.indexOf(row.id) >= 0 || this.excelValid.gradeIds.indexOf(row.id) >= 0) {
                 className = className + 'account-warning-row-bg'
                 className = className + 'account-warning-row-bg'
             } else {
             } else {
-                if (!(this.repeatAccounts.length == 0 || this.repeatAccounts.indexOf(row.id) == -1) || row.seatRepeat) {
+                if (!(this.repeatAccounts.length == 0 || this.repeatAccounts.indexOf(row.id) == -1) || row.seatRepeat || this.excelValid.idErr.includes(row.id)) {
                     className = className + 'account-error-row-bg '
                     className = className + 'account-error-row-bg '
                 }
                 }
                 if (row.classId == '' || row.classId == null || row.no == '' || row.no == null) {
                 if (row.classId == '' || row.classId == null || row.no == '' || row.no == null) {
@@ -257,8 +258,6 @@ export default {
                 if (flag) {
                 if (flag) {
                     // 处理表格导入数据类型
                     // 处理表格导入数据类型
                     this.tableData = results.filter(item => {
                     this.tableData = results.filter(item => {
-                        // let arr = item.id.split('#') //账号id不用#
-                        // if (arr.length == 2) {
                         for (let i of this.systemColumn) {
                         for (let i of this.systemColumn) {
                             if (i != 'no') {
                             if (i != 'no') {
                                 if (typeof item[i] === 'number') {
                                 if (typeof item[i] === 'number') {
@@ -272,9 +271,6 @@ export default {
                                 // item.pw = item.id
                                 // item.pw = item.id
                             }
                             }
                         }
                         }
-                        // } else {
-                        //     item._disabled = true
-                        // }
                         return item
                         return item
                     })
                     })
 
 
@@ -293,13 +289,30 @@ export default {
                         // 取出Excel重複的班級
                         // 取出Excel重複的班級
                         let classIds = []
                         let classIds = []
                         this.tableData.forEach((item) => {
                         this.tableData.forEach((item) => {
-                            if (classIds.indexOf(item.classId) < 0) { classIds.push(item.classId) }
+                            // if (classIds.indexOf(item.classId) < 0) { classIds.push(item.classId) }
+                            // 班级结构调整后判断班级唯一不能只是classId还需要搭配classYear
+                            if (classIds.length) {
+                                let res = classIds.find(classItem => {
+                                    return classItem.classId == item.classId && classItem.classYear == item.classYear
+                                })
+                                if (!res) {
+                                    classIds.push({
+                                        classId: item.classId,
+                                        classYear: item.classYear
+                                    })
+                                }
+                            } else {
+                                classIds.push({
+                                    classId: item.classId,
+                                    classYear: item.classYear
+                                })
+                            }
                         })
                         })
                         // 先篩選出會被修改的學生
                         // 先篩選出會被修改的學生
                         let updStuds = []
                         let updStuds = []
-                        classIds.forEach((id) => {
+                        classIds.forEach((classItem) => {
                             let stud = this.students.filter((studInfo) => {
                             let stud = this.students.filter((studInfo) => {
-                                return (id == studInfo.classNo)
+                                return (classItem.classId == studInfo.classNo && classItem.classYear == studInfo.classYear)
                             })
                             })
 
 
                             updStuds.push(...stud)
                             updStuds.push(...stud)
@@ -406,15 +419,16 @@ export default {
             this.file = null
             this.file = null
             this.tableData = []
             this.tableData = []
             this.tableTitle = [
             this.tableTitle = [
-                {
-                    type: 'selection',
-                    width: 80,
-                    align: 'center'
-                },
+                // {
+                //     type: 'selection',
+                //     width: 80,
+                //     align: 'center'
+                // },
                 {
                 {
                     title: this.$t('stuAccount.seatNo'),
                     title: this.$t('stuAccount.seatNo'),
                     key: 'no',
                     key: 'no',
-                    width: 80
+                    width: 80,
+                    align:'center'
                 },
                 },
                 {
                 {
                     title: this.$t('stuAccount.account'),
                     title: this.$t('stuAccount.account'),
@@ -429,7 +443,7 @@ export default {
                     key: 'name'
                     key: 'name'
                 },
                 },
                 {
                 {
-                    title: '学级',
+                    title: this.$t('stuAccount.academicYear'),
                     key: 'stuYear'
                     key: 'stuYear'
                 },
                 },
                 {
                 {
@@ -437,14 +451,14 @@ export default {
                     key: 'className'
                     key: 'className'
                 },
                 },
                 {
                 {
-                    title: '年级',
+                    title: this.$t('stuAccount.grade'),
                     slot: 'classYear'
                     slot: 'classYear'
                 },
                 },
                 {
                 {
                     title: this.$t('stuAccount.classroomCode'),
                     title: this.$t('stuAccount.classroomCode'),
-                    key: 'classId'
+                    key: 'classId',
+                    align:'center'
                 },
                 },
-
                 {
                 {
                     title: this.$t('stuAccount.abnormalStatus'),
                     title: this.$t('stuAccount.abnormalStatus'),
                     slot: 'status'
                     slot: 'status'
@@ -455,6 +469,7 @@ export default {
             let _this = this
             let _this = this
             var excelData = data
             var excelData = data
             let validFalg = false
             let validFalg = false
+            let zg = /^[0-9]+$/
             // 先歸零
             // 先歸零
             this.errNumReset()
             this.errNumReset()
             excelData.forEach((item, index, array) => {
             excelData.forEach((item, index, array) => {
@@ -475,6 +490,11 @@ export default {
                         }
                         }
                     }
                     }
 
 
+                    //ID格式检查(只能包含数字)
+                    if (!zg.test(item.id)) {
+                        _this.excelValid.idErr.push(item.id)
+                    }
+
                     // ID 重複
                     // ID 重複
                     let repID = array.filter((i, key) => {
                     let repID = array.filter((i, key) => {
                         return i.id == item.id && index != key
                         return i.id == item.id && index != key
@@ -543,9 +563,9 @@ export default {
     mounted() {
     mounted() {
     },
     },
     watch: {
     watch: {
-        period:{
-            handler(n,o){
-                this.tableData.forEach(item=>{
+        period: {
+            handler(n, o) {
+                this.tableData.forEach(item => {
                     item.periodId = this.period
                     item.periodId = this.period
                 })
                 })
             }
             }