sign.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <ui-group-option class="sign-guide">
  3. <div class="info">
  4. <div class="guide-cover">
  5. <img :src="getResources(getFileUrl(guide.cover))" />
  6. <ui-icon
  7. type="preview"
  8. class="icon"
  9. ctrl
  10. @click="playSceneGuide(paths, undefined, true)"
  11. v-if="paths.length"
  12. />
  13. </div>
  14. <div>
  15. <p v-show="!isEditTitle">{{ guide.title }}</p>
  16. <ui-input
  17. class="view-title-input"
  18. type="text"
  19. :modelValue="guide.title"
  20. :maxlength="15"
  21. @update:modelValue="(title: string) => $emit('updateTitle', title)"
  22. @blur="() => $emit('updateTitle', guide.title.trim())"
  23. v-show="isEditTitle"
  24. ref="inputRef"
  25. height="28px"
  26. />
  27. </div>
  28. </div>
  29. <div class="actions" v-if="edit">
  30. <ui-more
  31. :options="menus"
  32. style="margin-left: 20px"
  33. @click="(action: keyof typeof actions) => actions[action]()"
  34. />
  35. </div>
  36. </ui-group-option>
  37. </template>
  38. <script setup lang="ts">
  39. import { Guide, getGuidePaths } from "@/store";
  40. import { getFileUrl, saveAs } from "@/utils";
  41. import { getResource, getResources } from "@/env";
  42. import { computed, watchEffect, nextTick, ref } from "vue";
  43. import { playSceneGuide, isScenePlayIng, pauseSceneGuide } from "@/sdk";
  44. import { VideoRecorder } from "simaqcore";
  45. import useFocus from "bill/hook/useFocus";
  46. import { Message } from "bill/expose-common";
  47. import { ui18n } from "@/lang";
  48. const props = withDefaults(defineProps<{ guide: Guide; edit?: boolean }>(), {
  49. edit: true,
  50. });
  51. const inputRef = ref();
  52. const isEditTitle = useFocus(computed(() => inputRef.value?.vmRef.root));
  53. watchEffect(() => {
  54. if (!isEditTitle.value && !props.guide.title.trim().length) {
  55. isEditTitle.value = true;
  56. Message.warning(ui18n.t("guide.nameErr"));
  57. }
  58. });
  59. const emit = defineEmits<{
  60. (e: "updateTitle", t: string): void;
  61. (e: "delete"): void;
  62. (e: "play"): void;
  63. (e: "edit"): void;
  64. }>();
  65. const menus = [
  66. { label: ui18n.t("sys.rename"), value: "editTitle" },
  67. { label: ui18n.t("sys.edit"), value: "edit" },
  68. { label: ui18n.t("sys.del"), value: "delete" },
  69. ];
  70. const actions = {
  71. edit: () => emit("edit"),
  72. editTitle: () => {
  73. isEditTitle.value = true;
  74. },
  75. delete: () => emit("delete"),
  76. download: () => {
  77. const config: any = {
  78. // uploadUrl: '',
  79. // resolution: '4k',
  80. // autoDownload: false,
  81. // systemAudio: true,
  82. // debug: true,
  83. resolution: "4k",
  84. autoDownload: false,
  85. platform: "canvas",
  86. config: {
  87. frameRate: 60,
  88. canvasId: ".scene-canvas > canvas",
  89. },
  90. disbaledAudio: false,
  91. systemAudio: false,
  92. debug: false,
  93. };
  94. const videoRecorder = new VideoRecorder(config);
  95. videoRecorder.startRecord();
  96. let stopWatch: () => void;
  97. const stopRecord = () => {
  98. stopWatch && stopWatch();
  99. pauseSceneGuide();
  100. };
  101. videoRecorder.on("record", (blob) => {
  102. saveAs(
  103. new File([blob], ui18n.t("record.vName") + ".mp4", {
  104. type: "video/mp4; codecs=h264",
  105. }),
  106. props.guide.title + ".mp4"
  107. );
  108. });
  109. videoRecorder.off("*");
  110. videoRecorder.on("startRecord", () => {
  111. playSceneGuide(paths.value, undefined, true);
  112. stopWatch = watchEffect(() => {
  113. if (!isScenePlayIng.value) {
  114. videoRecorder.endRecord();
  115. nextTick(stopWatch);
  116. }
  117. });
  118. });
  119. videoRecorder.on("cancelRecord", stopRecord);
  120. videoRecorder.on("endRecord", stopRecord);
  121. },
  122. };
  123. const paths = computed(() => getGuidePaths(props.guide));
  124. </script>
  125. <style lang="scss" scoped>
  126. .sign-guide {
  127. display: flex;
  128. justify-content: space-between;
  129. align-items: center;
  130. padding: 20px 0;
  131. border-bottom: 1px solid var(--colors-border-color);
  132. &:first-child {
  133. border-top: 1px solid var(--colors-border-color);
  134. }
  135. .info {
  136. flex: 1;
  137. display: flex;
  138. align-items: center;
  139. .guide-cover {
  140. position: relative;
  141. &::after {
  142. content: "";
  143. position: absolute;
  144. inset: 0;
  145. background: rgba(0, 0, 0, 0.2);
  146. }
  147. .icon {
  148. position: absolute;
  149. z-index: 1;
  150. left: 50%;
  151. top: 50%;
  152. transform: translate(-50%, -50%);
  153. font-size: 16px;
  154. }
  155. img {
  156. width: 48px;
  157. height: 48px;
  158. object-fit: cover;
  159. border-radius: 4px;
  160. overflow: hidden;
  161. background-color: rgba(255, 255, 255, 0.6);
  162. display: block;
  163. }
  164. }
  165. div:not(.view-title-input) {
  166. margin-left: 10px;
  167. p {
  168. color: #fff;
  169. font-size: 14px;
  170. margin-bottom: 6px;
  171. }
  172. }
  173. }
  174. .actions {
  175. flex: none;
  176. }
  177. }
  178. </style>
  179. <style>
  180. .view-title-input.ui-input .text.suffix input {
  181. padding-right: 50px;
  182. }
  183. </style>