index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <MainPanel>
  3. <template v-slot:header>
  4. <Header :count="selects.length" :title="`已标注照片(${sortPhotos.length})`">
  5. <ui-button
  6. :type="selectMode ? 'primary' : 'normal'"
  7. @click="selectMode = !selectMode"
  8. width="96px"
  9. style="margin-right: 16px"
  10. >
  11. {{ selectMode ? '取消' : '选择' }}
  12. </ui-button>
  13. <ui-button
  14. v-if="!selectMode"
  15. type="primary"
  16. @click="router.push({name: writeRouteName.photos})"
  17. width="96px"
  18. >
  19. 新增
  20. </ui-button>
  21. </Header>
  22. </template>
  23. <div class="type-photos-layout">
  24. <div class="type-photos" v-for="typePhoto in typePhotos" :key="typePhoto.type">
  25. <p class="type-title">{{ typePhoto.type }}</p>
  26. <Photos
  27. class="type-photos-content"
  28. v-model:active="active"
  29. v-model:selects="selects"
  30. :select-mode="selectMode"
  31. :data="typePhoto.photos"
  32. >
  33. <template v-slot="{data}">
  34. <p>{{ data.title || '默认标题' }}</p>
  35. </template>
  36. </Photos>
  37. </div>
  38. </div>
  39. <ActionMenus class="select-menus" :menus="selectMenus" dire="row" v-if="selects.length" />
  40. </MainPanel>
  41. <FillSlide :data="sortPhotos" v-model:active="active" @quit="active = null" v-if="active">
  42. <template v-slot:foot>
  43. <ActionMenus class="menus" :menus="menus" dire="row" />
  44. </template>
  45. </FillSlide>
  46. </template>
  47. <script setup lang="ts">
  48. import MainPanel from '@/components/main-panel/index.vue'
  49. import FillSlide from '@/components/fill-slide/index.vue'
  50. import ActionMenus from "@/components/group-button/index.vue";
  51. import {types, accidentPhotos, AccidentPhoto} from '@/store/accidentPhotos'
  52. import UiIcon from "@/components/base/components/icon/index.vue";
  53. import {router, writeRouteName} from '@/router'
  54. import {computed, reactive, ref, watchEffect} from "vue";
  55. import {Mode} from '@/views/graphic/menus'
  56. import UiButton from "@/components/base/components/button/index.vue";
  57. import Photos from "@/components/photos/index.vue";
  58. import Header from "@/components/photos/header.vue";
  59. import ButtonPane from "@/components/button-pane/index.vue";
  60. import {useConfirm} from "@/hook";
  61. import {roadPhotos} from "@/store/roadPhotos";
  62. const sortPhotos = computed(() => {
  63. const photos = [...accidentPhotos.value]
  64. return photos.sort((a, b) =>
  65. types.indexOf(a.type) - types.indexOf(b.type)
  66. )
  67. })
  68. const typePhotos = computed(() =>
  69. types
  70. .map(type => ({
  71. type,
  72. photos: sortPhotos.value.filter(data => data.type === type)
  73. }))
  74. .filter(data => data.photos.length)
  75. )
  76. const selectMode = ref(false)
  77. const selects = ref<AccidentPhoto[]>([])
  78. const active = ref<AccidentPhoto>()
  79. const menus = [
  80. {
  81. key: "edit",
  82. icon: "edit",
  83. text: "修改",
  84. onClick: () => gotoDraw()
  85. },
  86. {
  87. key: "del",
  88. icon: "del",
  89. text: "删除",
  90. onClick: () => delPhoto()
  91. }
  92. ]
  93. const selectMenus = reactive([
  94. {
  95. key: "gen",
  96. icon: "photo",
  97. text: "生成A4",
  98. disabled: computed(() => selects.value.length > 2),
  99. onClick: () => {
  100. const params = {
  101. id1: selects.value[0].id,
  102. id2: selects.value.length === 1 ? '-1' : selects.value[1].id
  103. }
  104. router.push({ name: writeRouteName.gena4, params})
  105. }
  106. },
  107. {
  108. key: "del",
  109. text: "删除",
  110. icon: "del",
  111. onClick: () => delSelects()
  112. },
  113. ])
  114. watchEffect(() => {
  115. if (!selectMode.value) {
  116. selects.value = []
  117. }
  118. })
  119. const delPhotoRaw = (accidentPhoto = active.value) => {
  120. const index = accidentPhotos.value.indexOf(accidentPhoto)
  121. const reset = active.value ? accidentPhotos.value.indexOf(active.value) : -1
  122. if (~index) {
  123. accidentPhotos.value.splice(index, 1)
  124. }
  125. if (~reset) {
  126. console.log(reset)
  127. if (reset >= accidentPhotos.value.length) {
  128. if (accidentPhotos.value.length) {
  129. active.value = accidentPhotos.value[accidentPhotos.value.length - 1]
  130. } else {
  131. active.value = null
  132. }
  133. } else {
  134. active.value = accidentPhotos.value[reset]
  135. }
  136. }
  137. }
  138. const delPhoto = async (photo = active.value) => {
  139. if (await useConfirm(`确定要删除此数据?`)) {
  140. delPhotoRaw(photo)
  141. }
  142. }
  143. const delSelects = async () => {
  144. if (await useConfirm(`确定要删除这${selects.value.length}项数据?`)) {
  145. while (selects.value.length) {
  146. delPhotoRaw(selects.value[0])
  147. selects.value.shift()
  148. }
  149. }
  150. }
  151. const gotoDraw = () => {
  152. router.push({
  153. name: writeRouteName.graphic,
  154. params: {mode: Mode.Photo, id: active.value.id, action: 'update'}
  155. })
  156. }
  157. </script>
  158. <style scoped lang="scss">
  159. .type-photos-layout {
  160. position: absolute;
  161. top: calc(var(--header-top) + var(--editor-head-height));
  162. left: 0;
  163. right: 0;
  164. bottom: 0;
  165. overflow-y: auto;
  166. background: #2E2E2E;
  167. padding: 25px 0;
  168. }
  169. .type-photos-content {
  170. position: static;
  171. overflow: initial;
  172. background: none;
  173. p {
  174. color: #fff;
  175. font-size: 14px;
  176. margin-top: 8px;
  177. }
  178. }
  179. .menus {
  180. left: 50%;
  181. transform: translateX(-50%);
  182. bottom: var(--boundMargin);
  183. }
  184. .fun-ctrl {
  185. color: #fff;
  186. font-size: 20px;
  187. transition: color .3s ease;
  188. .icon {
  189. position: absolute;
  190. transform: translateX(-50%);
  191. }
  192. }
  193. .del {
  194. left: 50%;
  195. transform: translateX(-50%);
  196. bottom: var(--boundMargin);
  197. }
  198. .type-title {
  199. padding: 0 24px 2px;
  200. font-size: 16px;
  201. }
  202. .select-menus {
  203. left: 50%;
  204. transform: translateX(-50%);
  205. bottom: var(--boundMargin);
  206. }
  207. </style>