index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <RightFillPano>
  3. <ui-group title="初始画面" borderBottom>
  4. <ui-group-option>
  5. <div class="init-pic" :class="{ disabled: isEdit }">
  6. <img :src="getFileUrl(setting!.cover)" class="init-puc-cover" />
  7. <div class="init-pic-set" @click="enterSetPic">设置</div>
  8. </div>
  9. </ui-group-option>
  10. </ui-group>
  11. <ui-group title="设置天空">
  12. <ui-group-option>
  13. <selectBack :value="setting?.back || setting?.mapId ? [setting?.back, setting?.mapId] : ['dt', 1]" @update:value="changeBack" />
  14. </ui-group-option>
  15. </ui-group>
  16. <ui-group title="设置定位参照模型">
  17. <ui-group-option>
  18. <p class="model-name">模型名称</p>
  19. <div v-if="!isEditModelName" class="model-name-input" @click="enterSetModelName">
  20. <span v-if="setting?.locationModelName"><img src="@/assets/orientation.svg" alt="未设置" />{{ setting?.locationModelName }}</span>
  21. <span v-else><img src="@/assets/orientation.svg" alt="未设置" />未设置</span>
  22. </div>
  23. <div v-else class="model-name-input">
  24. <img src="@/assets/orientation.svg" alt="未设置" />
  25. <ui-input
  26. style="width: 100%;"
  27. type="text"
  28. :modelValue="setting?.locationModelName"
  29. :maxlength="100"
  30. height="40px"
  31. @update:modelValue="(locationModelName: string) => getLocationModelName(locationModelName)"
  32. />
  33. </div>
  34. </ui-group-option>
  35. </ui-group>
  36. </RightFillPano>
  37. </template>
  38. <script lang="ts" setup>
  39. import { RightFillPano } from "@/layout";
  40. import { enterEdit, enterOld, setting, isEdit, updataSetting } from "@/store";
  41. import { ref, watch } from "vue";
  42. import { togetherCallback, getFileUrl, loadPack } from "@/utils";
  43. import { showRightPanoStack, showRightCtrlPanoStack } from "@/env";
  44. import { analysisPose, sdk } from "@/sdk";
  45. import selectBack from "./select-back.vue";
  46. const enterSetPic = () => {
  47. enterEdit(
  48. togetherCallback([
  49. showRightPanoStack.push(ref(false)),
  50. showRightCtrlPanoStack.push(ref(false)),
  51. ])
  52. );
  53. enterOld(async () => {
  54. const dataURL = await sdk.screenshot(300, 150);
  55. const res = await fetch(dataURL);
  56. const blob = await res.blob();
  57. setting.value = {
  58. ...setting.value!,
  59. cover: { url: dataURL, blob },
  60. pose: analysisPose(sdk.getPose()),
  61. };
  62. await updataSetting();
  63. });
  64. };
  65. let locationModelName = setting.value!.locationModelName
  66. watch(() => setting.value!.locationModelName, (newVal) => {
  67. locationModelName = newVal;
  68. });
  69. let initBack = setting.value!.back;
  70. let initMapId = setting.value!.mapId;
  71. let isFirst = true;
  72. let isInPutFirst = true;
  73. let oldlocationModelName = JSON.parse(JSON.stringify(setting.value!.locationModelName))
  74. const isEditModelName = ref<boolean>(false);
  75. const changeBack = ([back, mapId]: [string | null, number | null]) => {
  76. setting.value!.back = back;
  77. setting.value!.mapId = mapId;
  78. if (isFirst) {
  79. let isSave = false;
  80. isFirst = false;
  81. enterEdit(() => {
  82. if (!isSave) {
  83. setting.value!.back = initBack;
  84. setting.value!.mapId = initMapId;
  85. }
  86. isFirst = true;
  87. });
  88. enterOld(async () => {
  89. initBack = setting.value!.back;
  90. initMapId = setting.value!.mapId;
  91. isSave = true;
  92. console.log(initBack, initMapId, locationModelName);
  93. await loadPack(updataSetting());
  94. });
  95. }
  96. };
  97. const enterSetModelName = () => {
  98. isEditModelName.value = true;
  99. let isSave = false;
  100. enterEdit(() => {
  101. if (!isSave) {
  102. // 不保存重置
  103. console.log(oldlocationModelName, 9999)
  104. setting.value!.locationModelName = oldlocationModelName;
  105. }
  106. isInPutFirst = true;
  107. isEditModelName.value = false;
  108. });
  109. };
  110. const getLocationModelName = (locationModelName: string) => {
  111. setting.value!.locationModelName = locationModelName;
  112. if(isInPutFirst){
  113. isInPutFirst = false
  114. enterOld(async () => {
  115. oldlocationModelName = locationModelName
  116. await updataSetting();
  117. });
  118. }
  119. };
  120. </script>
  121. <style scoped lang="scss">
  122. .init-pic {
  123. height: 150px;
  124. border-radius: 4px;
  125. overflow: hidden;
  126. position: relative;
  127. }
  128. .init-puc-cover {
  129. width: 100%;
  130. height: 100%;
  131. object-fit: cover;
  132. }
  133. .init-pic-set {
  134. position: absolute;
  135. bottom: 0;
  136. left: 0;
  137. right: 0;
  138. background-color: rgba(0, 0, 0, 0.5);
  139. font-size: 12px;
  140. color: #fff;
  141. line-height: 32px;
  142. z-index: 1;
  143. text-align: center;
  144. cursor: pointer;
  145. }
  146. .model-name{
  147. margin-bottom: 10px;
  148. }
  149. .model-name-input{
  150. height: 40px;
  151. display: flex;
  152. align-items: center;
  153. span{
  154. display: flex;
  155. align-items: center;
  156. }
  157. img{
  158. margin-right: 10px;
  159. }
  160. }
  161. </style>