index.vue 6.5 KB

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