header.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. console.log(origin, data.value, index);
  160. if (~index) {
  161. origin[index] = newData;
  162. } else {
  163. origin.push(newData);
  164. }
  165. data.value = newData;
  166. });
  167. const saveHandler = async () => {
  168. await saveStore();
  169. if (!isRoad.value) {
  170. await router.replace({
  171. name: isRoad.value ? writeRouteName.roads : writeRouteName.accidents,
  172. });
  173. } else {
  174. router.replace({
  175. name: writeRouteName.graphic,
  176. params: { mode: Mode.Road, id: data.value.id, action: "update" },
  177. });
  178. }
  179. };
  180. const createTable = async () => {
  181. await saveStore();
  182. await router.replace({
  183. name: writeRouteName.tabulation,
  184. params: { id: data.value.id },
  185. });
  186. };
  187. </script>
  188. <style lang="scss" scoped>
  189. .graphic-header {
  190. display: flex;
  191. position: relative;
  192. width: 100%;
  193. height: 100%;
  194. align-items: center;
  195. justify-content: center;
  196. }
  197. .actions {
  198. display: flex;
  199. }
  200. .action {
  201. font-size: 20px;
  202. margin: 0 15px;
  203. display: flex;
  204. flex-direction: column;
  205. align-items: center;
  206. position: relative;
  207. justify-content: center;
  208. p {
  209. font-size: 14px;
  210. text-align: center;
  211. }
  212. }
  213. .table,
  214. .title {
  215. position: absolute;
  216. top: 50%;
  217. transform: translateY(-50%);
  218. }
  219. .title {
  220. left: 0;
  221. display: flex;
  222. align-items: center;
  223. p {
  224. margin-left: 10px;
  225. }
  226. }
  227. .table {
  228. right: 0;
  229. }
  230. .save {
  231. margin-left: 16px;
  232. }
  233. .map-status {
  234. pointer-events: none;
  235. position: absolute;
  236. left: 100%;
  237. transform: translateX(-50%);
  238. bottom: 0;
  239. z-index: 1;
  240. }
  241. .head-icon {
  242. width: 32px;
  243. height: 32px;
  244. background: rgba(255, 255, 255, 0.1);
  245. border-radius: 24px 24px 24px 24px;
  246. font-size: 16px !important;
  247. display: flex;
  248. justify-content: center;
  249. align-items: center;
  250. margin-left: -3px;
  251. }
  252. .meterPerPixel {
  253. position: absolute;
  254. top: 100%;
  255. right: 24px;
  256. margin-top: 24px;
  257. pointer-events: none;
  258. font-size: 20px;
  259. font-weight: 400;
  260. line-height: 23px;
  261. }
  262. </style>
  263. <style lang="scss">
  264. .map-status.ui-input,
  265. .map-status.ui-input .checkbox {
  266. width: 12px;
  267. height: 7px;
  268. }
  269. .map-status.ui-input .checkbox input + .replace {
  270. border-radius: 4px;
  271. background-color: #7e7e7e;
  272. position: absolute;
  273. border: none;
  274. &:before {
  275. content: "";
  276. display: block;
  277. position: absolute;
  278. height: 5px;
  279. border-radius: 50%;
  280. width: 5px;
  281. background-color: #fff;
  282. top: 1px;
  283. left: 1px;
  284. transition: all 0.3s ease;
  285. }
  286. i {
  287. display: none;
  288. }
  289. &.checked {
  290. background-color: var(--colors-primary-base) !important;
  291. &:before {
  292. left: calc(100% - 6px);
  293. }
  294. }
  295. }
  296. .save-file.save {
  297. border-color: #3a3d3d;
  298. background-color: #3a3d3d !important;
  299. color: #fff;
  300. }
  301. </style>