index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <MainPanel>
  3. <template v-slot:header>
  4. <Header
  5. :count="selects.length"
  6. :title="`现场图管理(${sortPhotos.length})`"
  7. type="return"
  8. :on-back="() => onBack()"
  9. >
  10. <ui-button
  11. :type="selectMode ? 'primary' : 'normal'"
  12. @click="selectMode = !selectMode"
  13. width="96px"
  14. style="margin-right: 16px"
  15. v-if="sortPhotos.length"
  16. >
  17. {{ selectMode ? "取消" : "选择" }}
  18. </ui-button>
  19. <ui-button
  20. v-if="!selectMode"
  21. type="primary"
  22. @click="router.push({ name: writeRouteName.photos })"
  23. width="96px"
  24. >
  25. 新增
  26. </ui-button>
  27. <template v-slot:center="{ count }">
  28. <template v-if="count"> 已选择 {{ count }} 张 </template>
  29. <!-- <div v-else class="filter-type">
  30. <span
  31. :class="{ active: currentType === TypeEnum.Draw }"
  32. @click="() => (currentType = TypeEnum.Draw)"
  33. >绘图</span
  34. >
  35. <span
  36. :class="{ active: currentType === TypeEnum.Table }"
  37. @click="() => (currentType = TypeEnum.Table)"
  38. >制表</span
  39. >
  40. </div> -->
  41. </template>
  42. </Header>
  43. </template>
  44. <!-- :getURL="(data) => data?.table?.url || data.url" -->
  45. <Photos
  46. undata-msg="无现场图。请点击右上角按钮绘制现场图。"
  47. v-model:active="active"
  48. v-model:selects="selects"
  49. :select-mode="selectMode"
  50. :data="sortPhotos"
  51. :getURL="(data) => data.url"
  52. >
  53. <template v-slot="{ data }">
  54. <p v-if="currentType === TypeEnum.Table">
  55. <!-- {{ (data as any).title || "默认标题" }} -->
  56. </p>
  57. </template>
  58. </Photos>
  59. <ActionMenus
  60. class="select-menus"
  61. :menus="selectMenus"
  62. dire="row"
  63. v-if="selects.length"
  64. />
  65. </MainPanel>
  66. <!-- :getURL="(data) => data?.table?.url || data.url" -->
  67. <FillSlide
  68. :getURL="(data) => data.url"
  69. :data="sortPhotos"
  70. v-model:active="active"
  71. @quit="active = null"
  72. v-if="active"
  73. >
  74. <template v-slot:foot>
  75. <ActionMenus class="menus" :menus="menus" dire="row" />
  76. </template>
  77. <template v-slot:topRight>
  78. <ui-icon type="copy" @click="copyPhoto" />
  79. <ui-icon type="del" @click="delPhoto(active)" />
  80. </template>
  81. </FillSlide>
  82. </template>
  83. <script setup lang="ts">
  84. import MainPanel from "@/components/main-panel/index.vue";
  85. import FillSlide from "@/components/fill-slide/index.vue";
  86. import { roadPhotos, RoadPhoto } from "@/store/roadPhotos";
  87. import ActionMenus from "@/components/group-button/index.vue";
  88. import { readyRouteName, router, writeRouteName } from "@/router";
  89. import { computed, onDeactivated, reactive, ref, watchEffect } from "vue";
  90. import { Mode } from "@/views/graphic/menus";
  91. import UiButton from "@/components/base/components/button/index.vue";
  92. import Header from "@/components/photos/header.vue";
  93. import Photos from "@/components/photos/index.vue";
  94. import ButtonPane from "@/components/button-pane/index.vue";
  95. import UiIcon from "@/components/base/components/icon/index.vue";
  96. import { useConfirm } from "@/hook";
  97. import { api } from "@/store/sync";
  98. import { photos } from "@/store/photos";
  99. import { getId } from "@/utils";
  100. const enum TypeEnum {
  101. Draw = "draw",
  102. Table = "table",
  103. }
  104. const currentType = ref(TypeEnum.Draw);
  105. const sortPhotos = computed(
  106. () =>
  107. roadPhotos.value.sort((a, b) => (b.updateTime || b.time) - (a.updateTime || a.time))
  108. // .filter((item) => (currentType.value === TypeEnum.Draw ? !item.table : !!item.table))
  109. );
  110. const onBack = () => {
  111. router.replace(readyRouteName.scene);
  112. // let back = router.currentRoute.value.query.back;
  113. // if (back) {
  114. // router.back();
  115. // } else {
  116. // api.closePage();
  117. // }
  118. };
  119. const active = ref<RoadPhoto>();
  120. const selectMode = ref(false);
  121. const selects = ref<RoadPhoto[]>([]);
  122. const menus = computed(() => [
  123. // {
  124. // key: "copy",
  125. // icon: "copy",
  126. // text: "复制",
  127. // onClick: () => {
  128. // const copy = JSON.parse(JSON.stringify(active.value)) as RoadPhoto;
  129. // copy.id = getId();
  130. // copy.time = new Date().getTime();
  131. // roadPhotos.value.push(copy);
  132. // active.value = null;
  133. // // gotoDraw(copy);
  134. // },
  135. // },
  136. {
  137. key: "tabulation",
  138. icon: "tabulation",
  139. // hide: currentType.value === TypeEnum.Table,
  140. text: "制表",
  141. onClick: () => gotoDraw(active.value, true),
  142. },
  143. {
  144. key: "road",
  145. icon: "edit",
  146. text: "修改",
  147. onClick: () => gotoDraw(),
  148. },
  149. ]);
  150. const selectMenus = [
  151. {
  152. key: "del",
  153. icon: "del",
  154. text: "删除",
  155. onClick: () => delSelects(),
  156. },
  157. ];
  158. const copyPhoto = () => {
  159. const copy = JSON.parse(JSON.stringify(active.value)) as RoadPhoto;
  160. copy.id = getId();
  161. copy.time = new Date().getTime();
  162. roadPhotos.value.push(copy);
  163. active.value = null;
  164. // gotoDraw(copy);
  165. };
  166. watchEffect(() => {
  167. if (!selectMode.value) {
  168. selects.value = [];
  169. }
  170. });
  171. watchEffect(() => {
  172. const route = router.currentRoute.value;
  173. if (route.name === readyRouteName.roads) {
  174. console.log(route.params);
  175. if (route.params.type) {
  176. currentType.value = route.params.type as TypeEnum;
  177. }
  178. }
  179. });
  180. const delPhotoRaw = (roadPhoto = active.value) => {
  181. const index = roadPhotos.value.indexOf(roadPhoto);
  182. const reset = active.value ? roadPhotos.value.indexOf(active.value) : -1;
  183. if (~index) {
  184. roadPhotos.value.splice(index, 1);
  185. }
  186. if (~reset) {
  187. if (reset >= roadPhotos.value.length) {
  188. if (roadPhotos.value.length) {
  189. active.value = roadPhotos.value[roadPhotos.value.length - 1];
  190. } else {
  191. active.value = null;
  192. }
  193. } else {
  194. active.value = roadPhotos.value[reset];
  195. }
  196. }
  197. };
  198. const delPhoto = async (photo = active.value) => {
  199. if (await useConfirm(`确定要删除此数据?`)) {
  200. console.log(photo);
  201. delPhotoRaw(photo);
  202. }
  203. };
  204. const delSelects = async () => {
  205. if (await useConfirm(`确定要删除这${selects.value.length}项数据?`)) {
  206. while (selects.value.length) {
  207. delPhotoRaw(selects.value[0]);
  208. selects.value.shift();
  209. }
  210. if (!sortPhotos.value.length) {
  211. selectMode.value = false;
  212. }
  213. }
  214. };
  215. const gotoDraw = (road = active.value, forece = false) => {
  216. if (forece) {
  217. router.push({
  218. name: writeRouteName.tabulation,
  219. params: { id: road.id },
  220. });
  221. } else {
  222. router.push({
  223. name: writeRouteName.graphic,
  224. params: { mode: Mode.Road, id: road.id, action: "update" },
  225. });
  226. }
  227. // if (forece || road.table) {
  228. // router.push({
  229. // name: writeRouteName.tabulation,
  230. // params: { id: road.id },
  231. // });
  232. // } else {
  233. // router.push({
  234. // name: writeRouteName.graphic,
  235. // params: { mode: Mode.Road, id: road.id, action: "update" },
  236. // });
  237. // }
  238. };
  239. onDeactivated(() => {
  240. active.value = null;
  241. });
  242. </script>
  243. <style scoped lang="scss">
  244. .photo p {
  245. color: #fff;
  246. font-size: 14px;
  247. margin-top: 8px;
  248. height: 20px;
  249. word-break: keep-all; /* 不换行 */
  250. overflow: hidden;
  251. text-overflow: ellipsis;
  252. }
  253. .menus {
  254. left: 50%;
  255. transform: translateX(-50%);
  256. bottom: var(--boundMargin);
  257. }
  258. .fun-ctrl {
  259. color: #fff;
  260. font-size: 20px;
  261. transition: color 0.3s ease;
  262. .icon {
  263. position: absolute;
  264. transform: translateX(-50%);
  265. }
  266. }
  267. .del {
  268. left: 50%;
  269. transform: translateX(-50%);
  270. bottom: var(--boundMargin);
  271. }
  272. .select-menus {
  273. left: 50%;
  274. transform: translateX(-50%);
  275. bottom: var(--boundMargin);
  276. }
  277. .filter-type {
  278. span {
  279. display: inline-block;
  280. color: #ffffff;
  281. font-size: 16px;
  282. margin: 0 20px;
  283. &.active {
  284. position: relative;
  285. &::after {
  286. position: absolute;
  287. content: "";
  288. bottom: 0;
  289. margin-bottom: -14px;
  290. left: 0;
  291. right: 0;
  292. height: 4px;
  293. background: #1779ed;
  294. border-radius: 2px;
  295. }
  296. }
  297. }
  298. }
  299. </style>