// 压缩配置 Vue.component("http-compression-config-box", { props: ["v-compression-config", "v-is-location", "v-is-group"], mounted: function () { let that = this sortLoad(function () { that.initSortableTypes() }) }, data: function () { let config = this.vCompressionConfig if (config == null) { config = { isPrior: false, isOn: false, useDefaultTypes: true, types: ["brotli", "gzip", "zstd", "deflate"], level: 5, decompressData: false, gzipRef: null, deflateRef: null, brotliRef: null, minLength: {count: 1, "unit": "kb"}, maxLength: {count: 32, "unit": "mb"}, mimeTypes: ["text/*", "application/javascript", "application/json", "application/atom+xml", "application/rss+xml", "application/xhtml+xml", "font/*", "image/svg+xml"], extensions: [".js", ".json", ".html", ".htm", ".xml", ".css", ".woff2", ".txt"], exceptExtensions: [".apk", ".ipa"], conds: null, enablePartialContent: false } } if (config.types == null) { config.types = [] } if (config.mimeTypes == null) { config.mimeTypes = [] } if (config.extensions == null) { config.extensions = [] } let allTypes = [ { name: "Gzip", code: "gzip", isOn: true }, { name: "Deflate", code: "deflate", isOn: true }, { name: "Brotli", code: "brotli", isOn: true }, { name: "ZSTD", code: "zstd", isOn: true } ] let configTypes = [] config.types.forEach(function (typeCode) { allTypes.forEach(function (t) { if (typeCode == t.code) { t.isOn = true configTypes.push(t) } }) }) allTypes.forEach(function (t) { if (!config.types.$contains(t.code)) { t.isOn = false configTypes.push(t) } }) return { config: config, moreOptionsVisible: false, allTypes: configTypes } }, watch: { "config.level": function (v) { let level = parseInt(v) if (isNaN(level)) { level = 1 } else if (level < 1) { level = 1 } else if (level > 10) { level = 10 } this.config.level = level } }, methods: { isOn: function () { return ((!this.vIsLocation && !this.vIsGroup) || this.config.isPrior) && this.config.isOn }, changeExtensions: function (values) { values.forEach(function (v, k) { if (v.length > 0 && v[0] != ".") { values[k] = "." + v } }) this.config.extensions = values }, changeExceptExtensions: function (values) { values.forEach(function (v, k) { if (v.length > 0 && v[0] != ".") { values[k] = "." + v } }) this.config.exceptExtensions = values }, changeMimeTypes: function (values) { this.config.mimeTypes = values }, changeAdvancedVisible: function () { this.moreOptionsVisible = !this.moreOptionsVisible }, changeConds: function (conds) { this.config.conds = conds }, changeType: function () { this.config.types = [] let that = this this.allTypes.forEach(function (v) { if (v.isOn) { that.config.types.push(v.code) } }) }, initSortableTypes: function () { let box = document.querySelector("#compression-types-box") let that = this Sortable.create(box, { draggable: ".checkbox", handle: ".icon.handle", onStart: function () { }, onUpdate: function (event) { let checkboxes = box.querySelectorAll(".checkbox") let codes = [] checkboxes.forEach(function (checkbox) { let code = checkbox.getAttribute("data-code") codes.push(code) }) that.config.types = codes } }) } }, template: `
| 启用内容压缩 | 
					 | 
			
| 压缩级别 | 
					
					 级别越高,压缩比例越大。  | 
			
| 支持的扩展名 | 
					 含有这些扩展名的URL将会被压缩,不区分大小写。  | 
			
| 例外扩展名 | 
					 含有这些扩展名的URL将不会被压缩,不区分大小写。  | 
			
| 支持的MimeType | 
					 响应的Content-Type里包含这些MimeType的内容将会被压缩。  | 
			
| 压缩算法 | 
					 选择支持的压缩算法和优先顺序,拖动图表排序。  | 
			
| 支持已压缩内容 | 
					 支持对已压缩内容尝试重新使用新的算法压缩;不选中表示保留当前的压缩格式。  | 
			
| 内容最小长度 | 
					 0表示不限制,内容长度从文件尺寸或Content-Length中获取。  | 
			
| 内容最大长度 | 
					 0表示不限制,内容长度从文件尺寸或Content-Length中获取。  | 
			
| 支持Partial Content  | 
				
					 支持对分片内容(PartialContent)的压缩;除非客户端有特殊要求,一般不需要启用。  | 
			
| 匹配条件 | 
					 |