index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. <Photos
  24. v-model:active="active"
  25. v-model:selects="selects"
  26. :select-mode="selectMode"
  27. :data="sortPhotos"
  28. :getURL="data => data?.table?.url || data.url"
  29. >
  30. <template v-slot="{data}">
  31. <p>{{ data.title || '默认标题' }}</p>
  32. </template>
  33. </Photos>
  34. <ActionMenus class="select-menus" :menus="selectMenus" dire="row" v-if="selects.length" />
  35. </MainPanel>
  36. <FillSlide
  37. :getURL="data => data?.table?.url || data.url"
  38. :data="sortPhotos"
  39. v-model:active="active"
  40. @quit="active = null"
  41. v-if="active"
  42. >
  43. <template v-slot:foot>
  44. <ActionMenus class="menus" :menus="menus" dire="row" />
  45. </template>
  46. </FillSlide>
  47. </template>
  48. <script setup lang="ts">
  49. import MainPanel from '@/components/main-panel/index.vue'
  50. import FillSlide from '@/components/fill-slide/index.vue'
  51. import {roadPhotos, RoadPhoto} from '@/store/roadPhotos'
  52. import ActionMenus from "@/components/group-button/index.vue";
  53. import {router, writeRouteName} from '@/router'
  54. import {computed, ref, watchEffect} from "vue";
  55. import {Mode} from '@/views/graphic/menus'
  56. import UiButton from "@/components/base/components/button/index.vue";
  57. import Header from "@/components/photos/header.vue";
  58. import Photos from "@/components/photos/index.vue";
  59. import ButtonPane from "@/components/button-pane/index.vue";
  60. import UiIcon from "@/components/base/components/icon/index.vue";
  61. import {useConfirm} from "@/hook";
  62. const sortPhotos = computed(() => roadPhotos.value.reverse())
  63. const active = ref<RoadPhoto>()
  64. const selectMode = ref(false)
  65. const selects = ref<RoadPhoto[]>([])
  66. const menus = [
  67. {
  68. key: "road",
  69. icon: "edit",
  70. text: "修改",
  71. onClick: () => gotoDraw()
  72. },
  73. {
  74. key: "del",
  75. icon: "del",
  76. text: "删除",
  77. onClick: () => delPhoto()
  78. }
  79. ]
  80. const selectMenus = [
  81. {
  82. key: "del",
  83. icon: "del",
  84. text: "删除",
  85. onClick: () => delSelects()
  86. },
  87. ]
  88. watchEffect(() => {
  89. if (!selectMode.value) {
  90. selects.value = []
  91. }
  92. })
  93. const delPhotoRaw = (roadPhoto = active.value) => {
  94. const index = roadPhotos.value.indexOf(roadPhoto)
  95. const reset = active.value ? roadPhotos.value.indexOf(active.value) : -1
  96. if (~index) {
  97. roadPhotos.value.splice(index, 1)
  98. }
  99. if (~reset) {
  100. if (reset >= roadPhotos.value.length) {
  101. if (roadPhotos.value.length) {
  102. active.value = roadPhotos.value[roadPhotos.value.length - 1]
  103. } else {
  104. active.value = null
  105. }
  106. } else {
  107. active.value = roadPhotos.value[reset]
  108. }
  109. }
  110. }
  111. const delPhoto = async (photo = active.value) => {
  112. if (await useConfirm(`确定要删除此数据?`)) {
  113. delPhotoRaw(photo)
  114. }
  115. }
  116. const delSelects = async () => {
  117. if (await useConfirm(`确定要删除这${selects.value.length}项数据?`)) {
  118. while (selects.value.length) {
  119. delPhotoRaw(selects.value[0])
  120. selects.value.shift()
  121. }
  122. }
  123. }
  124. const gotoDraw = () => {
  125. router.push({
  126. name: writeRouteName.graphic,
  127. params: {mode: Mode.Road, id: active.value.id, action: 'update'}
  128. })
  129. }
  130. </script>
  131. <style scoped lang="scss">
  132. .photo p {
  133. color: #fff;
  134. font-size: 14px;
  135. margin-top: 8px;
  136. }
  137. .menus {
  138. left: 50%;
  139. transform: translateX(-50%);
  140. bottom: var(--boundMargin);
  141. }
  142. .fun-ctrl {
  143. color: #fff;
  144. font-size: 20px;
  145. transition: color .3s ease;
  146. .icon {
  147. position: absolute;
  148. transform: translateX(-50%);
  149. }
  150. }
  151. .del {
  152. left: 50%;
  153. transform: translateX(-50%);
  154. bottom: var(--boundMargin);
  155. }
  156. .select-menus {
  157. left: 50%;
  158. transform: translateX(-50%);
  159. bottom: var(--boundMargin);
  160. }
  161. </style>