upload-image-demo.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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>图片上传裁剪示例</title>
  7. <script src="/js/mp_base/base.js"></script>
  8. </head>
  9. <body>
  10. <div id="app" v-cloak>
  11. <div class="demo-container">
  12. <h2>图片和文件上传组件示例</h2>
  13. <!-- 单图上传 -->
  14. <h3>1. 圆形头像 (160x160) - 单图</h3>
  15. <table>
  16. <tr>
  17. <th>头像</th>
  18. <td>
  19. <ss-upload-image
  20. v-model="avatar1"
  21. :width="160"
  22. :height="160"
  23. shape="circle"
  24. :aspect-ratio="1"
  25. @updated="onImageUpdated"
  26. />
  27. <div style="margin-top: 10px; font-size: 12px; color: #666;">
  28. 当前值: {{ avatar1 || '未上传' }}
  29. </div>
  30. </td>
  31. </tr>
  32. </table>
  33. <h3>2. 方形头像 (120x120) - 单图</h3>
  34. <table>
  35. <tr>
  36. <th>艺术照</th>
  37. <td>
  38. <ss-upload-image
  39. v-model="avatar2"
  40. :width="120"
  41. :height="120"
  42. shape="square"
  43. :aspect-ratio="1"
  44. @updated="onImageUpdated"
  45. />
  46. <div style="margin-top: 10px; font-size: 12px; color: #666;">
  47. 当前值: {{ avatar2 || '未上传' }}
  48. </div>
  49. </td>
  50. </tr>
  51. </table>
  52. <h3>3. 矩形图片 (200x150, 4:3比例) - 单图</h3>
  53. <table>
  54. <tr>
  55. <th>证件照</th>
  56. <td>
  57. <ss-upload-image
  58. v-model="photo"
  59. :width="200"
  60. :height="150"
  61. shape="square"
  62. :aspect-ratio="4/3"
  63. :output-width="400"
  64. :output-height="300"
  65. @updated="onImageUpdated"
  66. />
  67. <div style="margin-top: 10px; font-size: 12px; color: #666;">
  68. 当前值: {{ photo || '未上传' }}
  69. </div>
  70. </td>
  71. </tr>
  72. </table>
  73. <!-- 多图上传 -->
  74. <h3>4. 多图上传 (最多9张) - 方形80x80</h3>
  75. <table>
  76. <tr>
  77. <th>相册</th>
  78. <td>
  79. <ss-upload-image
  80. v-model="gallery"
  81. :max="9"
  82. :width="80"
  83. :height="80"
  84. shape="square"
  85. :aspect-ratio="1"
  86. @updated="onImageUpdated"
  87. />
  88. <div style="margin-top: 10px; font-size: 12px; color: #666;">
  89. 当前值: {{ Array.isArray(gallery) ? gallery.join(', ') : (gallery || '未上传') }}
  90. </div>
  91. </td>
  92. </tr>
  93. </table>
  94. <h3>5. 多图上传 (最多3张) - 圆形100x100</h3>
  95. <table>
  96. <tr>
  97. <th>图集</th>
  98. <td>
  99. <ss-upload-image
  100. v-model="photoSet"
  101. :max="3"
  102. :width="100"
  103. :height="100"
  104. shape="circle"
  105. :aspect-ratio="1"
  106. @updated="onImageUpdated"
  107. />
  108. <div style="margin-top: 10px; font-size: 12px; color: #666;">
  109. 当前值: {{ Array.isArray(photoSet) ? photoSet.join(', ') : (photoSet || '未上传') }}
  110. </div>
  111. </td>
  112. </tr>
  113. </table>
  114. <!-- 文件上传 -->
  115. <h3>6. 单文件上传 (默认5MB)</h3>
  116. <table>
  117. <tr>
  118. <th>文档</th>
  119. <td>
  120. <ss-upload-file
  121. v-model="document"
  122. @updated="onFileUpdated"
  123. />
  124. <div style="margin-top: 10px; font-size: 12px; color: #666;">
  125. 当前值: {{ document || '未上传' }}
  126. </div>
  127. </td>
  128. </tr>
  129. </table>
  130. <h3>7. 多文件上传 (最多5个,限制10MB)</h3>
  131. <table>
  132. <tr>
  133. <th>附件</th>
  134. <td>
  135. <ss-upload-file
  136. v-model="attachments"
  137. :max="5"
  138. :max-size="10"
  139. @updated="onFileUpdated"
  140. />
  141. <div style="margin-top: 10px; font-size: 12px; color: #666;">
  142. 当前值: {{ Array.isArray(attachments) ? attachments.join(', ') : (attachments || '未上传') }}
  143. </div>
  144. </td>
  145. </tr>
  146. </table>
  147. <h3>8. 限制文件类型 (仅图片)</h3>
  148. <table>
  149. <tr>
  150. <th>图片文件</th>
  151. <td>
  152. <ss-upload-file
  153. v-model="imageFile"
  154. accept=".jpg,.jpeg,.png,.gif"
  155. @updated="onFileUpdated"
  156. />
  157. <div style="margin-top: 10px; font-size: 12px; color: #666;">
  158. 当前值: {{ imageFile || '未上传' }}
  159. </div>
  160. </td>
  161. </tr>
  162. </table>
  163. </div>
  164. </div>
  165. <script>
  166. SS.ready(function () {
  167. window.SS.dom.initializeFormApp({
  168. el: '#app',
  169. data() {
  170. return {
  171. // 单图上传
  172. avatar1: '',
  173. avatar2: '',
  174. photo: '',
  175. // 多图上传
  176. gallery: [],
  177. photoSet: [],
  178. // 文件上传
  179. document: '',
  180. attachments: [],
  181. imageFile: ''
  182. };
  183. },
  184. methods: {
  185. onImageUpdated(serverPath) {
  186. console.log('图片上传成功,服务器路径:', serverPath);
  187. alert('图片上传成功!路径:' + serverPath);
  188. },
  189. onFileUpdated(serverPath) {
  190. console.log('文件上传成功,服务器路径:', serverPath);
  191. alert('文件上传成功!路径:' + serverPath);
  192. }
  193. }
  194. });
  195. });
  196. </script>
  197. <style>
  198. [v-cloak] {
  199. display: none !important;
  200. }
  201. .demo-container {
  202. padding: 20px;
  203. }
  204. h2 {
  205. text-align: center;
  206. margin-bottom: 30px;
  207. color: #333;
  208. }
  209. h3 {
  210. margin-top: 30px;
  211. margin-bottom: 15px;
  212. color: #666;
  213. font-size: 18px;
  214. }
  215. table {
  216. margin-bottom: 30px;
  217. }
  218. </style>
  219. </body>
  220. </html>