<template>
	<el-input
		v-model="password"
		type="password"
		show-password
		v-bind="$attrs"
		@blur="encryptPassword"
	/>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const password = ref('')

const modelValue = defineModel<{ rsa_aesKey: string; cipher_text: string }>()

// 加密处理
const encryptPassword = () => {
	if (!password.value?.trim()) {
		return
	}

	/// 获取AES秘钥
	// @ts-ignore
	const aesKey = window?.BpmTools?.$generateAESKey()

	// 将AES秘钥加密
	// @ts-ignore
	const rsaAesKey = window?.BpmTools?.$encryptAESKey(aesKey)

	// 进行AES算法加密密码
	// @ts-ignore
	const newPwd = window?.BpmTools?.$encryptDataWithAES(aesKey, password.value)

	// rsaAesKey和newPwd构建db_password字段
	modelValue.value = {
		rsa_aesKey: rsaAesKey,
		cipher_text: newPwd
	}
}
</script>

<style scoped></style>
