import initCtx from "@/utils/ctx.js";

export default function () {
	const {utils, Tea} = initCtx(this)

	// 上传证书
	this.uploadCert = function () {
		utils.popup("/servers/certs/uploadPopup", {
			callback: function () {
				utils.success("上传成功", function () {
					utils.reload()
				})
			}
		})
	}

	// 批量上传证书
	this.uploadBatch = function () {
		utils.popup("/servers/certs/uploadBatchPopup", {
			callback: function () {
				utils.reload()
			}
		})
	}

	// 删除证书
	this.deleteCert = function (certId) {
		let that = this
		utils.confirm("确定要删除此证书吗？", function () {
			that.$post("/servers/certs/delete")
				.params({
					certId: certId
				})
				.refresh()
		})
	}

	// 查看证书
	this.viewCert = function (certId) {
		utils.popup("/servers/certs/certPopup?certId=" + certId, {
			width: "48em",
			height: "40em"
		})
	}

	// 修改证书
	this.updateCert = function (certId) {
		utils.popup("/servers/certs/updatePopup?certId=" + certId, {
			height: utils.POPUP_HEIGHT_LG,
			callback: function () {
				utils.success("修改成功", function () {
					utils.reload()
				})
			}
		})
	}
}