Vue.component("ssl-certs-box", { props: [ "v-certs", // 证书列表 "v-cert", // 单个证书 "v-protocol", // 协议:https|tls "v-view-size", // 弹窗尺寸:normal, mini "v-single-mode", // 单证书模式 "v-description", // 描述文字 "v-domains" // 搜索的域名列表或者函数 ], data: function () { let certs = this.vCerts if (certs == null) { certs = [] } if (this.vCert != null) { certs.push(this.vCert) } let description = this.vDescription if (description == null || typeof (description) != "string") { description = "" } return { certs: certs, description: description } }, methods: { certIds: function () { return this.certs.map(function (v) { return v.id }) }, // 删除证书 removeCert: function (index) { let that = this teaweb.confirm("确定删除此证书吗?证书数据仍然保留,只是当前服务不再使用此证书。", function () { that.certs.$remove(index) }) }, // 选择证书 selectCert: function () { let that = this let width = "54em" let height = "32em" let viewSize = this.vViewSize if (viewSize == null) { viewSize = "normal" } if (viewSize == "mini") { width = "35em" height = "20em" } let searchingDomains = [] if (this.vDomains != null) { if (typeof this.vDomains == "function") { let resultDomains = this.vDomains() if (resultDomains != null && typeof resultDomains == "object" && (resultDomains instanceof Array)) { searchingDomains = resultDomains } } else if (typeof this.vDomains == "object" && (this.vDomains instanceof Array)) { searchingDomains = this.vDomains } if (searchingDomains.length > 10000) { searchingDomains = searchingDomains.slice(0, 10000) } } let selectedCertIds = this.certs.map(function (cert) { return cert.id }) teaweb.popup("/servers/certs/selectPopup?viewSize=" + viewSize + "&searchingDomains=" + window.encodeURIComponent(searchingDomains.join(",")) + "&selectedCertIds=" + selectedCertIds.join(","), { width: width, height: height, callback: function (resp) { if (resp.data.cert != null) { that.certs.push(resp.data.cert) } if (resp.data.certs != null) { that.certs.$pushAll(resp.data.certs) } that.$forceUpdate() } }) }, // 上传证书 uploadCert: function () { let that = this teaweb.popup("/servers/certs/uploadPopup", { height: "28em", callback: function (resp) { teaweb.success("上传成功", function () { that.certs.push(resp.data.cert) }) } }) }, // 格式化时间 formatTime: function (timestamp) { return new Date(timestamp * 1000).format("Y-m-d") }, // 判断是否显示选择|上传按钮 buttonsVisible: function () { return this.vSingleMode == null || !this.vSingleMode || this.certs == null || this.certs.length == 0 } }, template: `
` })