index.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <RightFillPano>
  3. <template #header>
  4. <div class="btns header-btns">
  5. <ui-button class="start" @click="start" type="primary">开始录制</ui-button>
  6. </div>
  7. </template>
  8. <ui-group title="全部视频" class="tree" >
  9. <Draggable :list="records" draggable=".sign" itemKey="id">
  10. <template #item="{ element: record }">
  11. <Sign
  12. :record="getSignRecord(record)"
  13. :key="record.id"
  14. @delete="deleteRecord(record)"
  15. @updateTitle="title => record.title = title"
  16. @updateCover="cover => record.cover = cover"
  17. />
  18. </template>
  19. </Draggable>
  20. </ui-group>
  21. </RightFillPano>
  22. </template>
  23. <script lang="ts" setup>
  24. import { ref, watch } from 'vue'
  25. import { showMeasuresStack, showTaggingsStack } from '@/env'
  26. import { useViewStack } from '@/hook'
  27. import { diffArrayChange, togetherCallback } from '@/utils'
  28. import { RecordProcess } from './help'
  29. import { records, createRecord, Record, RecordStatus, autoSaveRecords, initialRecords, getRecordFragmentBlobs, isTemploraryID } from '@/store'
  30. import { RightFillPano } from '@/layout'
  31. import Draggable from 'vuedraggable'
  32. import Sign from './sign.vue'
  33. import { Dialog } from 'bill/index'
  34. initialRecords()
  35. const start = () => records.value.push(createRecord())
  36. const deleteRecord = async (record: Record) => {
  37. const isTemp = getRecordFragmentBlobs(record).length === 0 && isTemploraryID(record.id)
  38. if (isTemp || await Dialog.confirm('确定要删除视频吗?')) {
  39. const index = records.value.indexOf(record)
  40. if (~index) {
  41. records.value.splice(index, 1)
  42. }
  43. }
  44. }
  45. const getSignRecord = (record: Record): RecordProcess => ({
  46. ...record,
  47. immediately: record.status === RecordStatus.UN
  48. })
  49. const setOptions = [
  50. { value: 'tagging', label: '标注' },
  51. { value: 'measure', label: '测量' },
  52. ] as const
  53. type SetKey = typeof setOptions[number]['value']
  54. const setting = ref<SetKey[]>(['tagging', 'measure'])
  55. watch(setting, (setting, oldSetting = [], onCleanup) => {
  56. const { added } = diffArrayChange(setting, oldSetting)
  57. const pops = added.map(value => {
  58. if (value === 'measure') {
  59. return showMeasuresStack.push(ref(true))
  60. } else {
  61. return showTaggingsStack.push(ref(true))
  62. }
  63. })
  64. onCleanup(togetherCallback(pops))
  65. }, { flush: 'sync' })
  66. useViewStack(() => {
  67. const pop = showTaggingsStack.push(ref(false))
  68. return () => {
  69. setting.value = []
  70. pop()
  71. }
  72. })
  73. useViewStack(autoSaveRecords)
  74. </script>
  75. <style lang="scss" src="./style.scss" scoped>
  76. </style>