companyImg.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <template>
  2. <view class="switch-roles">
  3. <nav-bar title="公司信息" color="#000"></nav-bar>
  4. <view class="roles-content">
  5. <view class="content">
  6. <view class="progress-num"> <text>7</text>/8 </view>
  7. <view class="title">
  8. <view>展示公司照片</view>
  9. </view>
  10. <view class="desc">在公司主页上展示亮眼的照片,体现企业氛围与文化魅力;最多上传20张</view>
  11. <view class="content-index">
  12. <!-- 多图上传区域 -->
  13. <view class="upload-section">
  14. <view class="images-grid">
  15. <!-- 已上传的图片 -->
  16. <view
  17. class="image-item"
  18. v-for="(image, index) in imageList"
  19. :key="index"
  20. @click="previewImage(index)"
  21. >
  22. <image :src="image.url" mode="aspectFill" class="preview-image"></image>
  23. <view class="image-mask">
  24. <u-icon name="eye" color="#fff" size="30"></u-icon>
  25. </view>
  26. <view class="delete-btn" @click.stop="deleteImage(index)">
  27. <u-icon name="close" color="#fff" size="20"></u-icon>
  28. </view>
  29. </view>
  30. <!-- 添加图片按钮 -->
  31. <view
  32. class="upload-box"
  33. v-if="imageList.length < maxCount"
  34. @click="chooseImage"
  35. >
  36. <view class="upload-placeholder">
  37. <u-icon name="plus" color="#999" size="40"></u-icon>
  38. <text class="upload-text">添加照片</text>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- 上传计数 -->
  43. <view class="upload-count" v-if="imageList.length > 0">
  44. 已上传 {{ imageList.length }}/{{ maxCount }} 张
  45. </view>
  46. <!-- 上传进度 -->
  47. <view v-if="uploading" class="upload-progress">
  48. <view class="progress-bar">
  49. <view
  50. class="progress-inner"
  51. :style="{ width: uploadProgress + '%' }"
  52. ></view>
  53. </view>
  54. <text class="progress-text">{{ uploadProgress }}%</text>
  55. </view>
  56. </view>
  57. <!-- 注意事项 -->
  58. <view class="warning-box">
  59. <view class="warning-title">注意事项:</view>
  60. <view class="warning-list">
  61. <view class="warning-item">1. 请上传清晰且完整的图片</view>
  62. <view class="warning-item"
  63. >2.
  64. 请上传品牌相关的图片,含有其他内容将无法通过审核(包括但不限于含有水印、招聘信息、联系方式、二维码等相关内容)</view
  65. >
  66. <view class="warning-item"
  67. >3. 上传图片须符合中国相关法律法规,不得含有违法内容或不良信息</view
  68. >
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. <view class="submit-btn" :class="{ disabled: imageList.length === 0 }" @click="goJobPostingSecond"
  75. >下一步</view
  76. >
  77. </view>
  78. </template>
  79. <script>
  80. import navBar from "@/components/nav-bar/index.vue";
  81. export default {
  82. data() {
  83. return {
  84. text: "",
  85. imageList: [], // 上传的图片列表
  86. maxCount: 20, // 最大上传数量
  87. uploading: false, // 是否正在上传
  88. uploadProgress: 0, // 上传进度
  89. };
  90. },
  91. components: {
  92. navBar,
  93. },
  94. onLoad(options) {
  95. if (options.text) {
  96. this.text = options.text;
  97. }
  98. },
  99. methods: {
  100. // 选择图片
  101. chooseImage() {
  102. const that = this;
  103. const remainingCount = this.maxCount - this.imageList.length;
  104. uni.chooseImage({
  105. count: remainingCount, // 最多选择剩余数量
  106. sizeType: ["compressed"],
  107. sourceType: ["album", "camera"],
  108. success: (res) => {
  109. const tempFilePaths = res.tempFilePaths;
  110. // 批量上传图片
  111. that.uploadMultipleImages(tempFilePaths);
  112. },
  113. fail: (error) => {
  114. console.log("选择图片失败:", error);
  115. uni.showToast({
  116. title: "选择图片失败",
  117. icon: "none",
  118. });
  119. },
  120. });
  121. },
  122. // 批量上传图片
  123. uploadMultipleImages(filePaths) {
  124. const that = this;
  125. that.uploading = true;
  126. that.uploadProgress = 0;
  127. // 模拟上传进度
  128. const progressTimer = setInterval(() => {
  129. that.uploadProgress += 10;
  130. if (that.uploadProgress >= 90) {
  131. clearInterval(progressTimer);
  132. }
  133. }, 100);
  134. // 模拟批量上传成功
  135. setTimeout(() => {
  136. clearInterval(progressTimer);
  137. that.uploadProgress = 100;
  138. // 将新图片添加到列表
  139. const newImages = filePaths.map(filePath => ({
  140. url: filePath,
  141. // 实际开发中这里应该是服务器返回的URL
  142. }));
  143. that.imageList = [...that.imageList, ...newImages];
  144. setTimeout(() => {
  145. that.uploading = false;
  146. uni.showToast({
  147. title: `成功上传${newImages.length}张图片`,
  148. icon: "success",
  149. });
  150. }, 500);
  151. }, 1500);
  152. // 实际开发中应该使用下面的代码:
  153. /*
  154. let uploadedCount = 0;
  155. const totalCount = filePaths.length;
  156. filePaths.forEach((filePath, index) => {
  157. uni.uploadFile({
  158. url: '你的上传接口地址',
  159. filePath: filePath,
  160. name: 'file',
  161. formData: {
  162. 'type': 'company_photo'
  163. },
  164. success: (uploadRes) => {
  165. uploadedCount++;
  166. const data = JSON.parse(uploadRes.data);
  167. if (data.code === 200) {
  168. that.imageList.push({
  169. url: data.data.url
  170. });
  171. }
  172. // 更新进度
  173. that.uploadProgress = Math.floor((uploadedCount / totalCount) * 100);
  174. // 所有图片上传完成
  175. if (uploadedCount === totalCount) {
  176. that.uploading = false;
  177. uni.showToast({
  178. title: `成功上传${uploadedCount}张图片`,
  179. icon: 'success'
  180. });
  181. }
  182. },
  183. fail: (error) => {
  184. uploadedCount++;
  185. console.log(`第${index + 1}张图片上传失败:`, error);
  186. if (uploadedCount === totalCount) {
  187. that.uploading = false;
  188. uni.showToast({
  189. title: '部分图片上传失败',
  190. icon: 'none'
  191. });
  192. }
  193. }
  194. });
  195. });
  196. */
  197. },
  198. // 预览图片
  199. previewImage(index) {
  200. if (this.imageList.length > 0) {
  201. const urls = this.imageList.map(item => item.url);
  202. uni.previewImage({
  203. urls: urls,
  204. current: index,
  205. });
  206. }
  207. },
  208. // 删除图片
  209. deleteImage(index) {
  210. const that = this;
  211. uni.showModal({
  212. title: "提示",
  213. content: "确定要删除这张照片吗?",
  214. success: (res) => {
  215. if (res.confirm) {
  216. that.imageList.splice(index, 1);
  217. uni.showToast({
  218. title: "删除成功",
  219. icon: "success",
  220. });
  221. }
  222. },
  223. });
  224. },
  225. // 下一步
  226. goJobPostingSecond() {
  227. if (this.imageList.length === 0) {
  228. uni.showToast({
  229. title: "请上传公司照片",
  230. icon: "none",
  231. });
  232. return;
  233. }
  234. // 跳转到下一页,传递图片数据
  235. const imageUrls = this.imageList.map(item => item.url);
  236. uni.navigateTo({
  237. url: "/my/renzheng/mainWorkIntro?photos=" + encodeURIComponent(JSON.stringify(imageUrls)),
  238. });
  239. },
  240. },
  241. };
  242. </script>
  243. <style lang="scss" scoped>
  244. .switch-roles {
  245. background-color: #fff;
  246. position: absolute;
  247. left: 0;
  248. right: 0;
  249. top: 0;
  250. bottom: 0;
  251. display: flex;
  252. flex-direction: column;
  253. .roles-content {
  254. width: 100%;
  255. flex: 1;
  256. overflow: hidden;
  257. overflow-y: auto;
  258. .content {
  259. padding: 40rpx;
  260. box-sizing: border-box;
  261. display: flex;
  262. flex-direction: column;
  263. align-items: center;
  264. justify-content: center;
  265. .progress-num {
  266. color: #016bf6;
  267. font-family: DM Sans;
  268. font-size: 24rpx;
  269. font-weight: 500;
  270. width: 100%;
  271. padding-bottom: 20rpx;
  272. box-sizing: border-box;
  273. text {
  274. font-size: 48rpx;
  275. font-weight: 700;
  276. }
  277. }
  278. .title {
  279. color: #333;
  280. width: 100%;
  281. font-family: DM Sans;
  282. font-size: 48rpx;
  283. font-weight: 700;
  284. display: flex;
  285. justify-content: space-between;
  286. align-items: center;
  287. margin-bottom: 20rpx;
  288. }
  289. .desc {
  290. color: rgba(102, 102, 102, 1);
  291. width: 100%;
  292. font-family: DM Sans;
  293. font-size: 24rpx;
  294. font-weight: 400;
  295. line-height: 32rpx;
  296. letter-spacing: 0.5%;
  297. text-align: left;
  298. box-sizing: border-box;
  299. margin-bottom: 40rpx;
  300. }
  301. .content-index {
  302. width: 100%;
  303. .upload-section {
  304. margin-bottom: 20rpx;
  305. .images-grid {
  306. display: grid;
  307. grid-template-columns: repeat(4, 1fr);
  308. gap: 20rpx;
  309. margin-bottom: 20rpx;
  310. .image-item {
  311. width: 142rpx;
  312. height: 142rpx;
  313. border-radius: 8rpx;
  314. position: relative;
  315. overflow: hidden;
  316. .preview-image {
  317. width: 100%;
  318. height: 100%;
  319. }
  320. .image-mask {
  321. position: absolute;
  322. top: 0;
  323. left: 0;
  324. width: 100%;
  325. height: 100%;
  326. background: rgba(0, 0, 0, 0.3);
  327. display: flex;
  328. align-items: center;
  329. justify-content: center;
  330. opacity: 0;
  331. transition: opacity 0.3s;
  332. }
  333. .delete-btn {
  334. position: absolute;
  335. top: 8rpx;
  336. right: 8rpx;
  337. width: 30rpx;
  338. height: 30rpx;
  339. background: rgba(0, 0, 0, 0.5);
  340. border-radius: 50%;
  341. display: flex;
  342. align-items: center;
  343. justify-content: center;
  344. }
  345. &:active .image-mask {
  346. opacity: 1;
  347. }
  348. }
  349. .upload-box {
  350. width: 142rpx;
  351. height: 142rpx;
  352. border-radius: 8rpx;
  353. display: flex;
  354. align-items: center;
  355. justify-content: center;
  356. background: #eee;
  357. .upload-placeholder {
  358. display: flex;
  359. flex-direction: column;
  360. align-items: center;
  361. justify-content: center;
  362. .upload-text {
  363. color: #666;
  364. font-size: 20rpx;
  365. margin-top: 8rpx;
  366. font-family: DM Sans;
  367. }
  368. }
  369. }
  370. }
  371. .upload-count {
  372. color: #666;
  373. font-size: 24rpx;
  374. text-align: center;
  375. margin-bottom: 20rpx;
  376. }
  377. .upload-progress {
  378. display: flex;
  379. align-items: center;
  380. gap: 20rpx;
  381. .progress-bar {
  382. flex: 1;
  383. height: 8rpx;
  384. background: #f0f0f0;
  385. border-radius: 4rpx;
  386. overflow: hidden;
  387. .progress-inner {
  388. height: 100%;
  389. background: #016bf6;
  390. border-radius: 4rpx;
  391. transition: width 0.3s;
  392. }
  393. }
  394. .progress-text {
  395. color: #016bf6;
  396. font-size: 24rpx;
  397. min-width: 80rpx;
  398. }
  399. }
  400. }
  401. .warning-box {
  402. color: rgba(102, 102, 102, 1);
  403. font-family: DM Sans;
  404. font-size: 24rpx;
  405. font-weight: 400;
  406. line-height: 32rpx;
  407. .warning-item{
  408. margin-top: 8rpx;
  409. }
  410. }
  411. }
  412. }
  413. }
  414. .submit-btn {
  415. flex-shrink: 0;
  416. border-radius: 999px;
  417. background: #ff6600;
  418. color: rgba(255, 255, 255, 1);
  419. font-family: DM Sans;
  420. font-size: 32rpx;
  421. font-weight: 400;
  422. line-height: 48rpx;
  423. display: flex;
  424. justify-content: center;
  425. align-items: center;
  426. padding: 24rpx 32rpx;
  427. box-sizing: border-box;
  428. margin: 30rpx 40rpx;
  429. margin-top: 20rpx;
  430. &.disabled {
  431. background: #ccc;
  432. color: #999;
  433. }
  434. }
  435. }
  436. </style>