header.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <div v-if="data" class="graphic-header">
  3. <div class="title">
  4. <ui-icon class="head-icon" type="return" @click="router.back" />
  5. <p>{{ isRoad ? "现场绘图" : "事故照片" }}</p>
  6. </div>
  7. <div class="actions">
  8. <div
  9. v-for="menu in menus"
  10. :key="menu.text"
  11. :class="{ disabled: menu.disable }"
  12. class="action fun-ctrl"
  13. @click="menu.onClick"
  14. >
  15. <ui-icon :type="menu.icon" />
  16. <p>{{ menu.text }}</p>
  17. <ui-input
  18. v-if="menu.icon === 'map'"
  19. :modelValue="graphicState.showBackImage"
  20. class="map-status"
  21. type="checkbox"
  22. />
  23. </div>
  24. </div>
  25. <div class="table">
  26. <ui-input
  27. v-if="options"
  28. v-model="(data as AccidentPhoto).type"
  29. :options="options"
  30. height="32px"
  31. type="select"
  32. width="120px"
  33. />
  34. <ui-button
  35. :class="{ ['save-file']: isRoad }"
  36. :type="isRoad ? undefined : 'primary'"
  37. class="save"
  38. width="100px"
  39. @click="saveHandler"
  40. >
  41. {{ isRoad ? "保存" : "完成" }}
  42. </ui-button>
  43. <ui-button
  44. v-if="isRoad"
  45. class="save"
  46. type="primary"
  47. width="100px"
  48. @click="createTable"
  49. >
  50. 制表
  51. </ui-button>
  52. </div>
  53. <div
  54. class="meterPerPixel"
  55. v-if="currentMeterPerPixel && isRoad"
  56. :style="{ color: graphicState.showBackImage ? '#fff' : '#16181A' }"
  57. >
  58. 1 : {{ currentMeterPerPixel }}
  59. </div>
  60. </div>
  61. </template>
  62. <script lang="ts" setup>
  63. import UiIcon from "@/components/base/components/icon/index.vue";
  64. import UiButton from "@/components/base/components/button/index.vue";
  65. import { Mode } from "./menus";
  66. import { changeStore, drawRef, graphicState } from "@/hook/useGraphic";
  67. import { computed, onActivated, onDeactivated, ref, watchEffect } from "vue";
  68. import { router, writeRouteName } from "@/router";
  69. import { AccidentPhoto, accidentPhotos, types } from "@/store/accidentPhotos";
  70. import { useData } from "./data";
  71. import UiInput from "@/components/base/components/input/index.vue";
  72. import { roadPhotos } from "@/store/roadPhotos";
  73. import { uploadImage } from "@/store/sync";
  74. import { genUseLoading } from "@/hook";
  75. import { dataService } from "@/graphic/Service/DataService";
  76. const data = useData();
  77. const mode = computed(() => Number(router.currentRoute.value.params.mode) as Mode);
  78. const isRoad = computed(() => mode.value === Mode.Road);
  79. const options = computed(() =>
  80. !isRoad.value ? types.map((t) => ({ label: t, value: t })) : null
  81. );
  82. const currentMeterPerPixel = ref();
  83. let interval;
  84. onActivated(() => {
  85. interval = setInterval(() => {
  86. if (drawRef.value) {
  87. const coordinate = drawRef.value.coordinate;
  88. const p1 = coordinate.getXYFromScreen({ x: 0, y: 0 });
  89. const p2 = coordinate.getXYFromScreen({ x: 0, y: 1 });
  90. const num = Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
  91. const meterPerPixel = (num * coordinate.res * 100) / coordinate.ratio / 100;
  92. currentMeterPerPixel.value = Math.round(1 / meterPerPixel);
  93. }
  94. }, 200);
  95. });
  96. onDeactivated(() => clearInterval(interval));
  97. const backImageChang = (show) => {
  98. dataService.setGridDisplay(!show);
  99. drawRef.value.uiControl.menu_backgroundImg(show);
  100. };
  101. watchEffect(() => {
  102. if (data.value && drawRef.value) {
  103. backImageChang(true);
  104. }
  105. });
  106. type Menu = { disable?: boolean; text: string; icon: string; onClick: () => void };
  107. const menus = computed<Menu[]>(() => {
  108. const menus = [
  109. {
  110. text: "",
  111. icon: "backout",
  112. disable: !graphicState.value.canRevoke,
  113. onClick: () => {
  114. drawRef.value.uiControl.menu_revoke();
  115. changeStore();
  116. },
  117. },
  118. {
  119. text: "",
  120. icon: "redo",
  121. disable: !graphicState.value.canRecovery,
  122. onClick: () => {
  123. drawRef.value.uiControl.menu_recovery();
  124. changeStore();
  125. },
  126. },
  127. {
  128. text: "",
  129. icon: "clear",
  130. onClick: () => {
  131. drawRef.value.uiControl.menu_clear();
  132. changeStore();
  133. },
  134. },
  135. {
  136. icon: "reset",
  137. text: "",
  138. onClick: () => drawRef.value.uiControl.menu_view_reset(),
  139. },
  140. ];
  141. if (isRoad.value) {
  142. menus.splice(menus.length - 1, 0, {
  143. icon: "map",
  144. text: ``,
  145. onClick: () => backImageChang(!graphicState.value.showBackImage),
  146. });
  147. }
  148. return menus;
  149. });
  150. const saveStore = genUseLoading(async () => {
  151. const newData = {
  152. ...data.value,
  153. data: JSON.parse(JSON.stringify(drawRef.value.load.save())),
  154. };
  155. const blob = await drawRef.value.uiControl.screenShot();
  156. newData.url = await uploadImage(blob);
  157. const origin = isRoad.value ? roadPhotos.value : accidentPhotos.value;
  158. const index = origin.indexOf(data.value);
  159. if (~index) {
  160. origin[index] = newData;
  161. } else {
  162. origin.push(newData);
  163. }
  164. });
  165. const saveHandler = async () => {
  166. await saveStore();
  167. if (!isRoad.value) {
  168. await router.replace({
  169. name: isRoad.value ? writeRouteName.roads : writeRouteName.accidents,
  170. });
  171. } else {
  172. router.replace({
  173. name: writeRouteName.graphic,
  174. params: { mode: Mode.Road, id: data.value.id, action: "update" },
  175. });
  176. }
  177. };
  178. const createTable = async () => {
  179. await saveStore();
  180. await router.replace({
  181. name: writeRouteName.tabulation,
  182. params: { id: data.value.id },
  183. });
  184. };
  185. </script>
  186. <style lang="scss" scoped>
  187. .graphic-header {
  188. display: flex;
  189. position: relative;
  190. width: 100%;
  191. height: 100%;
  192. align-items: center;
  193. justify-content: center;
  194. }
  195. .actions {
  196. display: flex;
  197. }
  198. .action {
  199. font-size: 20px;
  200. margin: 0 15px;
  201. display: flex;
  202. flex-direction: column;
  203. align-items: center;
  204. position: relative;
  205. justify-content: center;
  206. p {
  207. font-size: 14px;
  208. text-align: center;
  209. }
  210. }
  211. .table,
  212. .title {
  213. position: absolute;
  214. top: 50%;
  215. transform: translateY(-50%);
  216. }
  217. .title {
  218. left: 0;
  219. display: flex;
  220. align-items: center;
  221. p {
  222. margin-left: 10px;
  223. }
  224. }
  225. .table {
  226. right: 0;
  227. }
  228. .save {
  229. margin-left: 16px;
  230. }
  231. .map-status {
  232. pointer-events: none;
  233. position: absolute;
  234. left: 100%;
  235. transform: translateX(-50%);
  236. bottom: 0;
  237. z-index: 1;
  238. }
  239. .head-icon {
  240. width: 32px;
  241. height: 32px;
  242. background: rgba(255, 255, 255, 0.1);
  243. border-radius: 24px 24px 24px 24px;
  244. font-size: 16px !important;
  245. display: flex;
  246. justify-content: center;
  247. align-items: center;
  248. margin-left: -3px;
  249. }
  250. .meterPerPixel {
  251. position: absolute;
  252. top: 100%;
  253. right: 24px;
  254. margin-top: 24px;
  255. pointer-events: none;
  256. font-size: 20px;
  257. font-weight: 400;
  258. line-height: 23px;
  259. }
  260. </style>
  261. <style lang="scss">
  262. .map-status.ui-input,
  263. .map-status.ui-input .checkbox {
  264. width: 12px;
  265. height: 7px;
  266. }
  267. .map-status.ui-input .checkbox input + .replace {
  268. border-radius: 4px;
  269. background-color: #7e7e7e;
  270. position: absolute;
  271. border: none;
  272. &:before {
  273. content: "";
  274. display: block;
  275. position: absolute;
  276. height: 5px;
  277. border-radius: 50%;
  278. width: 5px;
  279. background-color: #fff;
  280. top: 1px;
  281. left: 1px;
  282. transition: all 0.3s ease;
  283. }
  284. i {
  285. display: none;
  286. }
  287. &.checked {
  288. background-color: var(--colors-primary-base) !important;
  289. &:before {
  290. left: calc(100% - 6px);
  291. }
  292. }
  293. }
  294. .save-file.save {
  295. border-color: #3a3d3d;
  296. background-color: #3a3d3d !important;
  297. color: #fff;
  298. }
  299. </style>