GameView.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <script setup>
  2. // todo:这里的逻辑大多是从移动端代码搬运来的,其实用不到。只要保留关闭的接口给unity就行了!
  3. import { ref, onMounted } from 'vue'
  4. import { useRouter } from 'vue-router'
  5. import useSizeAdapt from "@/useFunctions/useSizeAdapt.js"
  6. const isShowToastFromGame = ref(false)
  7. const input1 = ref("")
  8. const input2 = ref("")
  9. const input1Ref = ref(null)
  10. const input2Ref = ref(null)
  11. const router = useRouter()
  12. const { windowSizeInCssForRef, windowSizeWhenDesignForRef } = useSizeAdapt()
  13. const handleInput1 = () => {
  14. console.log("第一个框得内容", input1.value)
  15. if (input1.value.length >= 7) {
  16. input1.value = input1.value.slice(0, 7) // 限制输入长度
  17. // input2Ref.value.focus() // 聚焦到第二个输入框
  18. }
  19. }
  20. const checkInput1 = (event) => {
  21. if (event.key === "Backspace" && input1.value.length === 0) {
  22. input2.value = "" // 清空第二个输入框
  23. input1Ref.value.focus() // 聚焦回到第一个输入框
  24. }
  25. }
  26. const handleInput2 = () => {
  27. // 这里可以添加类似的逻辑,但通常不需要,因为我们假设第二个输入框不会自动跳转回去
  28. if (input2.value.length >= 7) {
  29. input2.value = input2.value.slice(0, 7)
  30. }
  31. }
  32. const checkInput2 = (event) => {
  33. if (event.key === "Backspace" && input2.value.length === 0) {
  34. input1Ref.value.focus() // 如果需要从第二个输入框清空后聚焦回第一个输入框
  35. }
  36. }
  37. const saveTitle = () => {
  38. var iframe = document.getElementById("gameIframe")
  39. var iframeWindow = iframe.contentWindow || window.frames["yourIframeId"]
  40. if (iframeWindow) {
  41. iframeWindow.saveTitle(
  42. input1.value + "\n" + '线上创作'
  43. )
  44. isShowToastFromGame.value = false
  45. }
  46. }
  47. onMounted(() => {
  48. window.isShowToastFromGame = () => {
  49. isShowToastFromGame.value = true
  50. input1.value = ""
  51. input2.value = ""
  52. }
  53. window.closeGame = () => {
  54. router.go('-1')
  55. }
  56. })
  57. </script>
  58. <template>
  59. <div class="game-box">
  60. <iframe
  61. id="gameIframe"
  62. :src="`./game/index.html`"
  63. />
  64. <!-- edit弹框 -->
  65. <div
  66. v-show="isShowToastFromGame"
  67. class="edit-box"
  68. >
  69. <div class="input-box">
  70. <input
  71. ref="input1Ref"
  72. v-model="input1"
  73. @input="handleInput1"
  74. @keyup="checkInput1"
  75. >
  76. <!-- <input
  77. ref="input2Ref"
  78. v-model="input2"
  79. :readonly="input1.length < 7"
  80. @input="handleInput2"
  81. @keyup="checkInput2"
  82. > -->
  83. <div class="tips">
  84. 请输入内容
  85. </div>
  86. </div>
  87. <div
  88. class="cencel-btn"
  89. @click="isShowToastFromGame = false"
  90. >
  91. 取消
  92. </div>
  93. <div
  94. class="yes-btn"
  95. @click="saveTitle"
  96. >
  97. 保存
  98. </div>
  99. </div>
  100. </div>
  101. </template>
  102. <style lang='less' scoped>
  103. .game-box {
  104. width: 100%;
  105. height: 100%;
  106. position: relative;
  107. > iframe {
  108. width: 100%;
  109. height: 100%;
  110. position: absolute;
  111. top: 0;
  112. left: 0;
  113. }
  114. .edit-box {
  115. width: 125%;
  116. height: 35vh;
  117. display: flex;
  118. flex-direction: column;
  119. justify-content: center;
  120. align-items: center;
  121. background: url(@/assets/images/game-tip.png);
  122. background-size: 100% 100%;
  123. position: absolute;
  124. top: 50%;
  125. left: 50%;
  126. transform: translate(-50%, -50%);
  127. z-index: 2;
  128. font-family: "KaiTi";
  129. > .input-box {
  130. width: 50%;
  131. display: flex;
  132. flex-direction: column;
  133. margin-bottom: 10%;
  134. margin-right: 5%;
  135. > input {
  136. width: 100%;
  137. height: 45px;
  138. background: none;
  139. border: none;
  140. font-size: 20px;
  141. white-space: pre-wrap;
  142. color: white;
  143. border-bottom: 1px solid rgba(255, 255, 255, 0.548);
  144. font-family: "KaiTi";
  145. letter-spacing: 2px;
  146. }
  147. .tips {
  148. font-family: "KaiTi";
  149. font-size: 14px;
  150. margin-top: calc(
  151. 5 / v-bind("windowSizeWhenDesignForRef") *
  152. v-bind("windowSizeInCssForRef")
  153. );
  154. color: rgba(255, 255, 255, 0.418);
  155. }
  156. }
  157. > textarea {
  158. width: 34%;
  159. height: 40%;
  160. background: none;
  161. border: none;
  162. font-size: 20px;
  163. white-space: pre-wrap;
  164. }
  165. > .cencel-btn {
  166. // width: calc(70 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  167. // height: calc(30 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  168. background: url(@/assets/images/game-tip-cancel.png);
  169. background-size: 100% 100%;
  170. display: flex;
  171. justify-content: center;
  172. align-items: center;
  173. color: #ffffff;
  174. position: absolute;
  175. left: 30%;
  176. bottom: calc(
  177. 60 / v-bind("windowSizeWhenDesignForRef") *
  178. v-bind("windowSizeInCssForRef")
  179. );
  180. padding: 5px 10px;
  181. font-family: "KaiTi";
  182. }
  183. > .yes-btn {
  184. // width: calc(70 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  185. // height: calc(30 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  186. background: url(@/assets/images/game-tip-yes.png);
  187. background-size: 100% 100%;
  188. display: flex;
  189. justify-content: center;
  190. align-items: center;
  191. color: #f4e09d;
  192. position: absolute;
  193. right: 38%;
  194. bottom: calc(
  195. 60 / v-bind("windowSizeWhenDesignForRef") *
  196. v-bind("windowSizeInCssForRef")
  197. );
  198. padding: 5px 10px;
  199. font-family: "KaiTi";
  200. }
  201. }
  202. }
  203. </style>