Эх сурвалжийг харах

学校通知限制上传文件类型为图片

zhuth 6 жил өмнө
parent
commit
a46eb79eba

+ 2 - 1
frontend/pc-web/app/view/Interaction/notice/SchoolNotice.js

@@ -77,7 +77,8 @@ Ext.define('school.view.interaction.notice.SchoolNotice', {
             }, {
                 xtype: 'mfilefield',
                 name: 'notify_files',
-                fieldLabel: '附件'
+                fieldLabel: '附件',
+                fileRegex: /\.(jpeg|jpg|png|gif)$/
             }],
             applyBtns: [{
                 apply: true,

+ 39 - 30
frontend/pc-web/app/view/core/form/field/FileField.js

@@ -15,39 +15,48 @@ Ext.define('school.view.core.form.field.FileField', {
 		this.cls = '';
 		this.title = this.title || '附件';
 		this._title = this.title;
+		this.fileRegex = this.fileRegex || /\.*$/;
+		this.items = [{
+			xtype: 'form',
+			columnWidth: 1,
+			frame: false,
+			border: false,
+			minHeight: 22,
+			bodyStyle: 'padding:2px;background:#f7f7f7',
+			layout: 'hbox',
+			items: [{
+				xtype: 'hidden',
+				name: 'value'
+			}, {
+				xtype: 'filefield',
+				name: 'file',
+				cls:'x-form-filefield',
+				buttonText: '浏览文件(≤20MB)',
+				buttonOnly: true,
+				hideLabel: true,
+				buttonConfig:{
+					cls:'x-filefield-button'
+				},
+				regex: this.fileRegex,
+				regexText: "不支持的文件类型",
+				listeners: {
+					change: function(field, value){
+						if(!value) {
+							return;
+						}
+						if(field.validate()) {
+							field.ownerCt.ownerCt.upload(field.ownerCt, field);
+						}else {
+							field.reset();
+							school.util.BaseUtil.showErrorToast('不支持的文件类型');
+						}
+					}
+				}
+			}]
+		}];
 		this.callParent(arguments);
 	},
 	layout:'column',
-	items: [{
-		xtype: 'form',
-		columnWidth: 1,
-		frame: false,
-		border: false,
-		minHeight: 22,
-		bodyStyle: 'padding:2px;background:#f7f7f7',
-		layout: 'hbox',
-		items: [{
-			xtype: 'hidden',
-			name: 'value'
-		}, {
-			xtype: 'filefield',
-			name: 'file',
-			cls:'x-form-filefield',
-			buttonText: '浏览文件(≤20MB)',
-			buttonOnly: true,
-			hideLabel: true,
-			buttonConfig:{
-				cls:'x-filefield-button'
-			},
-			listeners: {
-				change: function(field){
-					if(!!field.value){
-						field.ownerCt.ownerCt.upload(field.ownerCt, field);
-					}
-				}
-			}
-		}]
-	}],
 	setValue: function(value){
 		this.value = value;
 		this.getValueField().setValue(value);