GameView.vue 5.6 KB

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