meeting-tpl-h5.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <template v-if="form.img">
  3. <div class="flex1" style="overflow: auto;">
  4. <TelViewTem @selectArea="selectArea" :enableDraw="enableDraw" bgColor="#fff" :bgSrc="form.img">
  5. <DragResizeRotate v-if="form.bgm" v-model="form.bgmRact" @activated="activatedBgm($event)" @deactivated="deactivatedBgm">
  6. <div class="w-100% h-100% d-flex j-c a-c">
  7. <img class="w-100% h-100%" src="@/assets/images/bg_music_icon.png" />
  8. </div>
  9. </DragResizeRotate>
  10. <template v-for="(item, index) in form?.events" :key="index">
  11. <DragResizeRotate v-model="form.events[index]" @delete="deleteItemEvents($event, index, item)" @activated="activated($event, index)" @deactivated="deactivated"></DragResizeRotate>
  12. </template>
  13. </TelViewTem>
  14. </div>
  15. </template>
  16. <template v-else>
  17. <div @click="addImgBg" class="bg-#f7f7f7 flex1 w-750 mb-10 c-s-p d-flex a-c j-c">
  18. <div class="c-666 f-s-18 u-s-n">点击此处上传图片</div>
  19. </div>
  20. </template>
  21. </template>
  22. <script setup lang="ts">
  23. import { httpRequests } from '@/utils/httpRequests';
  24. import { importFileGetUrls } from '@/utils/models';
  25. const emit = defineEmits<{
  26. (e: 'update:modelValue', value: any): void,
  27. (e: 'activated', value: any): void
  28. (e: 'deactivated'): void
  29. (e: 'deleteItemEvents', value: any): void,
  30. (e: 'muisc', value: any): void
  31. }>();
  32. const props = defineProps<{
  33. modelValue: any
  34. }>();
  35. const eventDefault = {
  36. id: '',
  37. eventName: '',
  38. params: {
  39. phone: '',
  40. url: '',
  41. },
  42. x: 0,
  43. y: 0,
  44. w: 100,
  45. h: 100,
  46. };
  47. const form = ref<any>(props.modelValue || { img: '', events: [] });
  48. const enableDraw = ref(true);
  49. const selectArea = (area: any) => {
  50. if (area.rect.w < 20 || area.rect.h < 20) {
  51. return;
  52. }
  53. form.value.events.push({ ...eventDefault, id: new Date().getTime() + '_btn_drap', ...area.rect });
  54. }
  55. const activated = (event, index) => {
  56. enableDraw.value = false;
  57. emit('activated', form.value.events[index] || { id: '' });
  58. }
  59. const activatedBgm = (event) => {
  60. enableDraw.value = false;
  61. }
  62. const deactivated = () => {
  63. enableDraw.value = true;
  64. emit('deactivated');
  65. }
  66. const deactivatedBgm = async () => {
  67. enableDraw.value = true;
  68. const musicParams = {
  69. id: form.value.id,
  70. bgmRact: form.value.bgmRact || {
  71. x: 100,
  72. y: 650,
  73. w: 50,
  74. h: 50
  75. },
  76. bgm: form.value.bgm || null
  77. };
  78. const saveRes = await httpRequests.post('/dgtmedicine/trainpage/setBgm', musicParams);
  79. if (saveRes && saveRes.code === 200) {
  80. // 更新背景音乐事件
  81. emit('muisc', form.value);
  82. }
  83. emit('deactivated');
  84. }
  85. const deleteItemEvents = (event: any, index: number, item: any) => {
  86. form.value.events.splice(index, 1);
  87. emit('deleteItemEvents', item);
  88. emit('update:modelValue', form.value);
  89. }
  90. const clickInfo = () => {
  91. console.log(form.value);
  92. }
  93. const addImgBg = async () => {
  94. const res: any[] = await importFileGetUrls(['png', 'jpg', 'jpeg'], false);
  95. if (res.length) {
  96. res.forEach(element => {
  97. if (element.data?.url) {
  98. form.value.img = element.data.url;
  99. }
  100. });
  101. }
  102. }
  103. watch(() => props.modelValue, (val) => {
  104. form.value = val || { img: '', events: [] };
  105. }, { deep: true });
  106. </script>
  107. <style scoped lang="scss"></style>