share.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <el-form ref="form" label-width="80px" class="share-from">
  3. <el-form-item label="链接">
  4. <el-input :modelValue="shareLink" disabled />
  5. </el-form-item>
  6. <el-form-item label="密码">
  7. <el-input
  8. :modelValue="randCode"
  9. @input="(val: string) => filterPSW(val)"
  10. placeholder="请输入密码"
  11. style="width: 120px"
  12. />
  13. </el-form-item>
  14. <el-form-item>
  15. <p class="maker">
  16. 注:链接可发送给有需要的人员,需使用密码访问。有效期
  17. <b style="color: #26559b">14</b>
  18. 天,过期后不可访问。
  19. </p>
  20. </el-form-item>
  21. </el-form>
  22. </template>
  23. <script setup lang="ts">
  24. import { computed, onMounted, ref, watchEffect } from "vue";
  25. import { EPSW } from "@/constant/REG";
  26. import { ElMessage } from "element-plus";
  27. import { copyText } from "@/util";
  28. import { getQuery } from "@/view/case/help";
  29. import { Fire, getFire } from "@/app/fire/store/fire";
  30. import { getCaseSharePWD, setCaseSharePWD } from "@/store/case";
  31. import { QuiskExpose } from "@/helper/mount";
  32. const props = defineProps<{ caseId: number }>();
  33. const randCode = ref("");
  34. const oldRandCode = ref("");
  35. const shareLink = computed(() => getQuery(props.caseId));
  36. const filterPSW = (val: string) => {
  37. if (val.length > 4) {
  38. return;
  39. } else if (EPSW.REG.test(val.substr(val.length - 1))) {
  40. randCode.value = val;
  41. } else {
  42. ElMessage.error(EPSW.tip);
  43. }
  44. };
  45. defineExpose<QuiskExpose>({
  46. async submit() {
  47. if (!randCode.value || randCode.value.length !== 4) {
  48. ElMessage.error("请输入四位数的密码!");
  49. throw "请输入四位数的密码!";
  50. }
  51. if (randCode.value !== oldRandCode.value) {
  52. await setCaseSharePWD({
  53. caseId: props.caseId,
  54. randCode: randCode.value,
  55. });
  56. }
  57. const result = `链接:${shareLink.value} 密码:${randCode.value}`;
  58. copyText(result);
  59. ElMessage.success("链接复制成功");
  60. return result;
  61. },
  62. });
  63. watchEffect(async () => {
  64. if (shareLink.value) {
  65. const code = await getCaseSharePWD({ caseId: props.caseId });
  66. oldRandCode.value = randCode.value = code;
  67. }
  68. });
  69. </script>