test2.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  6. <title>Test2 - 第三层页面</title>
  7. <!-- 微信 JS-SDK -->
  8. <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  9. <!-- Vue 3 CDN -->
  10. <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  11. <!-- H5工具函数库 -->
  12. <script src="../js/utils/h5-bridge.js"></script>
  13. </head>
  14. <body>
  15. <div id="app">
  16. <div class="container">
  17. <h1>📋 Test2 页面</h1>
  18. <p>这是第三层页面,最深层级的业务页面</p>
  19. <div class="nav-info">
  20. <div class="breadcrumb">
  21. <span>Home</span> → <span>Test1</span> → <span class="current">Test2</span>
  22. </div>
  23. <div class="level-info">
  24. 当前层级:第3层 | 这里模拟表单提交等业务操作
  25. </div>
  26. </div>
  27. <div class="business-section">
  28. <h3>🏢 业务操作区</h3>
  29. <div class="form-group">
  30. <label>模拟表单数据:</label>
  31. <input v-model="formData.title" @input="saveFormData" placeholder="请输入标题" class="form-input">
  32. <textarea v-model="formData.content" @input="saveFormData" placeholder="请输入内容" class="form-textarea"></textarea>
  33. <!-- 显示已选择的图片 -->
  34. <div v-if="formData.images.length > 0" class="images-section">
  35. <label>已选择的图片 ({{ formData.images.length }}张):</label>
  36. <div class="images-list">
  37. <div v-for="(image, index) in formData.images" :key="index" class="image-item">
  38. <span class="image-index">{{ index + 1 }}.</span>
  39. <span class="image-path">{{ image.path }}</span>
  40. <button @click="removeImage(index)" class="remove-btn">❌</button>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. <div class="button-group">
  47. <button class="btn success" @click="submitForm">
  48. ✅ 提交表单
  49. </button>
  50. <button class="btn warning" @click="chooseImage">
  51. 🖼️ 选择图片 ({{ formData.images.length }})
  52. </button>
  53. <button class="btn info" @click="scanCode">
  54. 📷 扫码
  55. </button>
  56. <button class="btn light" @click="clearFormData">
  57. 🗑️ 清除表单
  58. </button>
  59. <button class="btn secondary" @click="goBackToTest1">
  60. ⬅️ 返回Test1
  61. </button>
  62. <button class="btn danger" @click="goBackToMiniProgram">
  63. 🔙 返回小程序
  64. </button>
  65. </div>
  66. </div>
  67. </div>
  68. <script>
  69. const { createApp } = Vue
  70. createApp({
  71. data() {
  72. return {
  73. logs: [],
  74. formData: {
  75. title: '',
  76. content: '',
  77. images: [] // 存储选择的图片
  78. }
  79. }
  80. },
  81. mounted() {
  82. // 初始化页面
  83. initPage('test2', this.handleResult)
  84. // 恢复表单数据(简化版)
  85. this.loadFormData()
  86. },
  87. methods: {
  88. // 处理操作结果
  89. handleResult(data) {
  90. const { action, success, result, error, count, paths } = data
  91. if (success) {
  92. switch (action) {
  93. case 'scanCode':
  94. console.log(`📷 扫码成功: ${result}`)
  95. // 将扫码结果填入表单
  96. if (result) {
  97. this.formData.content += `\n扫码结果: ${result}`
  98. this.saveFormData() // 保存表单数据
  99. }
  100. break
  101. case 'chooseImage':
  102. console.log(`🖼️ 选择图片成功: ${count}张`)
  103. if (paths && paths.length > 0) {
  104. alert(JSON.stringify(paths))
  105. // 添加图片到数组中
  106. this.formData.images.push({
  107. path: paths[0],
  108. timestamp: Date.now()
  109. })
  110. console.log(`📁 已添加图片 ${this.formData.images.length}: ${paths[0]}`)
  111. this.saveFormData() // 保存表单数据
  112. }
  113. break
  114. default:
  115. console.log(`✅ ${action} 操作成功`)
  116. }
  117. } else {
  118. console.error(`❌ ${action} 操作失败: ${error}`)
  119. }
  120. },
  121. // 提交表单
  122. submitForm() {
  123. if (!this.formData.title.trim()) {
  124. return
  125. }
  126. // 模拟提交成功后清除数据并返回小程序
  127. setTimeout(() => {
  128. this.clearFormData() // 提交成功后清除保存的数据
  129. goBack('表单提交完成')
  130. }, 1000)
  131. },
  132. // 移除图片
  133. removeImage(index) {
  134. this.formData.images.splice(index, 1)
  135. this.saveFormData()
  136. },
  137. // 选择图片
  138. chooseImage() {
  139. chooseImage('从Test2页面选择图片')
  140. },
  141. // 扫码
  142. scanCode() {
  143. scanCode('从Test2页面扫码')
  144. },
  145. // 返回Test1页面
  146. goBackToTest1() {
  147. window.location.href = './test1.html?from=test2'
  148. },
  149. // 返回Home页面
  150. goBackToHome() {
  151. window.location.href = './home.html?from=test2'
  152. },
  153. // 返回小程序
  154. goBackToMiniProgram() {
  155. goBack('从Test2页面返回')
  156. },
  157. // 保存表单数据到localStorage
  158. saveFormData() {
  159. try {
  160. localStorage.setItem('test2_form_data', JSON.stringify(this.formData))
  161. console.log('💾 表单数据已保存')
  162. } catch (error) {
  163. console.error('保存表单数据失败:', error)
  164. }
  165. },
  166. // 从localStorage恢复表单数据
  167. loadFormData() {
  168. try {
  169. const savedData = localStorage.getItem('test2_form_data')
  170. if (savedData) {
  171. this.formData = { ...this.formData, ...JSON.parse(savedData) }
  172. this.addLog(`📥 恢复表单数据: ${this.formData.images.length}张图片`)
  173. }
  174. } catch (error) {
  175. console.error('恢复表单数据失败:', error)
  176. }
  177. },
  178. // 清除保存的表单数据
  179. clearFormData() {
  180. try {
  181. localStorage.removeItem('test2_form_data')
  182. this.formData = {
  183. title: '',
  184. content: '',
  185. images: []
  186. }
  187. } catch (error) {
  188. console.error('清除表单数据失败:', error)
  189. }
  190. },
  191. }
  192. }).mount('#app')
  193. </script>
  194. <style>
  195. * {
  196. margin: 0;
  197. padding: 0;
  198. box-sizing: border-box;
  199. }
  200. body {
  201. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  202. background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 50%, #fecfef 100%);
  203. min-height: 100vh;
  204. padding: 20px;
  205. }
  206. .container {
  207. max-width: 600px;
  208. margin: 0 auto;
  209. background: white;
  210. border-radius: 12px;
  211. padding: 24px;
  212. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  213. }
  214. h1 {
  215. text-align: center;
  216. color: #333;
  217. margin-bottom: 8px;
  218. }
  219. p {
  220. text-align: center;
  221. color: #666;
  222. margin-bottom: 24px;
  223. }
  224. .nav-info {
  225. background: #f8f9fa;
  226. border-radius: 8px;
  227. padding: 16px;
  228. margin-bottom: 24px;
  229. }
  230. .breadcrumb {
  231. font-size: 14px;
  232. color: #666;
  233. margin-bottom: 8px;
  234. }
  235. .breadcrumb .current {
  236. color: #e91e63;
  237. font-weight: 500;
  238. }
  239. .level-info {
  240. font-size: 12px;
  241. color: #999;
  242. }
  243. .business-section {
  244. background: #fff3cd;
  245. border-radius: 8px;
  246. padding: 16px;
  247. margin-bottom: 24px;
  248. }
  249. .business-section h3 {
  250. color: #856404;
  251. margin-bottom: 16px;
  252. }
  253. .form-group {
  254. display: flex;
  255. flex-direction: column;
  256. gap: 12px;
  257. }
  258. .form-group label {
  259. font-weight: 500;
  260. color: #333;
  261. }
  262. .form-input, .form-textarea {
  263. padding: 12px;
  264. border: 1px solid #ddd;
  265. border-radius: 6px;
  266. font-size: 14px;
  267. }
  268. .form-textarea {
  269. min-height: 80px;
  270. resize: vertical;
  271. }
  272. .images-section {
  273. margin-top: 16px;
  274. padding: 12px;
  275. background: #f0f8ff;
  276. border-radius: 6px;
  277. }
  278. .images-list {
  279. margin-top: 8px;
  280. }
  281. .image-item {
  282. display: flex;
  283. align-items: center;
  284. padding: 8px;
  285. background: white;
  286. border-radius: 4px;
  287. margin-bottom: 8px;
  288. border: 1px solid #e0e0e0;
  289. }
  290. .image-index {
  291. font-weight: 500;
  292. color: #666;
  293. margin-right: 8px;
  294. min-width: 20px;
  295. }
  296. .image-path {
  297. flex: 1;
  298. font-size: 12px;
  299. color: #333;
  300. word-break: break-all;
  301. }
  302. .remove-btn {
  303. background: none;
  304. border: none;
  305. cursor: pointer;
  306. font-size: 12px;
  307. padding: 4px;
  308. margin-left: 8px;
  309. }
  310. .button-group {
  311. display: grid;
  312. grid-template-columns: 1fr 1fr;
  313. gap: 12px;
  314. margin-bottom: 32px;
  315. }
  316. .btn {
  317. padding: 12px 16px;
  318. border: none;
  319. border-radius: 8px;
  320. font-size: 14px;
  321. font-weight: 500;
  322. cursor: pointer;
  323. transition: all 0.2s;
  324. }
  325. .btn.primary { background: #007AFF; color: white; }
  326. .btn.secondary { background: #6c757d; color: white; }
  327. .btn.success { background: #28a745; color: white; }
  328. .btn.warning { background: #ffc107; color: #212529; }
  329. .btn.info { background: #17a2b8; color: white; }
  330. .btn.danger { background: #dc3545; color: white; }
  331. .btn.light { background: #f8f9fa; color: #333; border: 1px solid #ddd; }
  332. .btn:hover {
  333. transform: translateY(-1px);
  334. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  335. }
  336. .log-section {
  337. border-top: 1px solid #eee;
  338. padding-top: 24px;
  339. }
  340. .log-section h3 {
  341. color: #333;
  342. margin-bottom: 16px;
  343. }
  344. .log-container {
  345. background: #f8f9fa;
  346. border-radius: 8px;
  347. padding: 16px;
  348. max-height: 250px;
  349. overflow-y: auto;
  350. }
  351. .log-item {
  352. display: flex;
  353. margin-bottom: 8px;
  354. font-size: 12px;
  355. }
  356. .log-time {
  357. color: #999;
  358. margin-right: 12px;
  359. min-width: 80px;
  360. }
  361. .log-message {
  362. color: #333;
  363. }
  364. @media (max-width: 480px) {
  365. .button-group {
  366. grid-template-columns: 1fr;
  367. }
  368. }
  369. </style>
  370. </body>
  371. </html>