|
|
@@ -22,7 +22,7 @@
|
|
|
</template>
|
|
|
<script setup lang="ts">
|
|
|
import { appConstant } from "@/app";
|
|
|
-import { computed, onMounted, ref } from "vue";
|
|
|
+import { computed, onMounted, ref, watch, toRefs } from "vue";
|
|
|
import { EPSW } from "@/constant/REG";
|
|
|
import { ElMessage } from "element-plus";
|
|
|
import { copyText } from "@/util";
|
|
|
@@ -31,10 +31,16 @@ import { Fire, getFire } from "@/app/fire/store/fire";
|
|
|
import { getCaseSharePWD, setCaseSharePWD } from "@/store/case";
|
|
|
import { QuiskExpose } from "@/helper/mount";
|
|
|
|
|
|
-const props = defineProps<{ caseId: number, projectName?: string }>();
|
|
|
-const randCode = ref("");
|
|
|
+const emit = defineEmits(['update:shareAuthCode']);
|
|
|
+const props = defineProps<{ caseId: number, shareAuthCode?: string, projectName?: string }>();
|
|
|
+const randCode = ref(props.shareAuthCode || '');
|
|
|
const oldRandCode = ref("");
|
|
|
const appId = import.meta.env.VITE_APP_APP || 'fire'
|
|
|
+console.log(props, 'shareAuthCode');
|
|
|
+// 监听 props 变化,同步到子组件内部
|
|
|
+watch(() => props.shareAuthCode, (newVal) => {
|
|
|
+ randCode.value = newVal || '';
|
|
|
+});
|
|
|
const shareLink = computed(() => {
|
|
|
const base = location.origin;
|
|
|
const p = md5(randCode.value || "");
|
|
|
@@ -50,13 +56,22 @@ const filterPSW = (val: string) => {
|
|
|
return;
|
|
|
} else if (EPSW.REG.test(val.substr(val.length - 1))) {
|
|
|
randCode.value = val;
|
|
|
+ emit('update:shareAuthCode', val);
|
|
|
} else {
|
|
|
ElMessage.error(EPSW.tip);
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
+function generateFourDigitString() {
|
|
|
+ // 生成 0 ~ 9999 的随机整数
|
|
|
+ const num = Math.floor(Math.random() * 10000);
|
|
|
+ // 补前导零,确保长度为 4
|
|
|
+ return num.toString().padStart(4, '0');
|
|
|
+}
|
|
|
+function updateShare() {
|
|
|
+ getCaseSharePWD({ caseId: props.caseId, password: randCode.value })
|
|
|
+ }
|
|
|
defineExpose<QuiskExpose>({
|
|
|
- async submit() {
|
|
|
+ async submit(save = false) {
|
|
|
if (!randCode.value || randCode.value.length !== 4) {
|
|
|
ElMessage.error("请输入四位数的密码!");
|
|
|
throw "请输入四位数的密码!";
|
|
|
@@ -67,17 +82,19 @@ defineExpose<QuiskExpose>({
|
|
|
randCode: randCode.value,
|
|
|
});
|
|
|
}
|
|
|
- const result = `${appId=='appId'?'案件名称':'起火对象'}:${props.projectName || ''} 链接:${shareLink.value} 密码:${randCode.value}`;
|
|
|
+ const result = `${appId=='criminal'?'案件名称':'起火对象'}:${props.projectName || ''} 链接:${shareLink.value} 密码:${randCode.value}`;
|
|
|
copyText(result);
|
|
|
ElMessage.success("链接复制成功");
|
|
|
+ // if(save) updateShare()
|
|
|
return result;
|
|
|
- },
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
onMounted(async () => {
|
|
|
try {
|
|
|
- const code = await getCaseSharePWD({ caseId: props.caseId });
|
|
|
- oldRandCode.value = randCode.value = code || "";
|
|
|
+ // const code = await getCaseSharePWD({ caseId: props.caseId });
|
|
|
+ // let code = generateFourDigitString();
|
|
|
+ // oldRandCode.value = randCode.value = code || "";
|
|
|
} catch (e) {
|
|
|
// 忽略错误,保持手动输入密码
|
|
|
}
|