companyImg.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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. companyData:{}
  90. };
  91. },
  92. components: {
  93. navBar,
  94. },
  95. onLoad(options) {
  96. if (options.companyData) {
  97. this.companyData = JSON.parse(options.companyData);
  98. }
  99. },
  100. methods: {
  101. // 选择图片
  102. chooseImage() {
  103. const that = this;
  104. const remainingCount = this.maxCount - this.imageList.length;
  105. // 1. 先判断系统类型,区分Android/iOS权限
  106. const systemInfo = uni.getSystemInfoSync();
  107. const isAndroid = systemInfo.system.includes('Android');
  108. const permissionType = isAndroid ? 'storage' : 'photos'; // Android=存储,iOS=相册
  109. // 2. 权限检查(复用之前封装的 checkPermission 函数)
  110. const hasPermission = this.$queue.checkPermission(
  111. permissionType,
  112. isAndroid
  113. ? '选择/拍摄照片需要相机/相册权限,用于上传企业主页照片' // Android 专属提示
  114. : '选择/拍摄照片需要相机/相册权限,用于上传企业主页照片'
  115. );
  116. if (!hasPermission) {
  117. uni.showToast({ title: '未获取权限,无法选择照片', icon: 'none' });
  118. return;
  119. }
  120. uni.chooseImage({
  121. count: remainingCount, // 最多选择剩余数量
  122. sizeType: ["compressed"],
  123. sourceType: ["album", "camera"],
  124. success: (res) => {
  125. const tempFilePaths = res.tempFilePaths;
  126. // 批量上传图片
  127. that.uploadMultipleImages(tempFilePaths);
  128. },
  129. fail: (error) => {
  130. console.log("选择图片失败:", error);
  131. uni.showToast({
  132. title: "选择图片失败",
  133. icon: "none",
  134. });
  135. },
  136. });
  137. },
  138. // 批量上传图片
  139. uploadMultipleImages(filePaths) {
  140. const that = this;
  141. that.uploading = true;
  142. that.uploadProgress = 0;
  143. // 模拟上传进度
  144. // const progressTimer = setInterval(() => {
  145. // that.uploadProgress += 10;
  146. // if (that.uploadProgress >= 90) {
  147. // clearInterval(progressTimer);
  148. // }
  149. // }, 100);
  150. // 模拟批量上传成功
  151. // setTimeout(() => {
  152. // clearInterval(progressTimer);
  153. // that.uploadProgress = 100;
  154. // // 将新图片添加到列表
  155. // const newImages = filePaths.map(filePath => ({
  156. // url: filePath,
  157. // // 实际开发中这里应该是服务器返回的URL
  158. // }));
  159. // that.imageList = [...that.imageList, ...newImages];
  160. // setTimeout(() => {
  161. // that.uploading = false;
  162. // uni.showToast({
  163. // title: `成功上传${newImages.length}张图片`,
  164. // icon: "success",
  165. // });
  166. // }, 500);
  167. // }, 1500);
  168. // 实际开发中应该使用下面的代码:
  169. let uploadedCount = 0;
  170. const totalCount = filePaths.length;
  171. filePaths.forEach((filePath, index) => {
  172. this.$queue.uploadFile(filePath,(path)=>{
  173. if(path) {
  174. uploadedCount++;
  175. that.imageList.push({
  176. url: path
  177. });
  178. // 更新进度
  179. that.uploadProgress = Math.floor((uploadedCount / totalCount) * 100);
  180. // 所有图片上传完成
  181. if (uploadedCount === totalCount) {
  182. that.uploading = false;
  183. uni.showToast({
  184. title: `成功上传${uploadedCount}张图片`,
  185. icon: 'success'
  186. });
  187. }
  188. }
  189. else {
  190. uploadedCount++;
  191. console.log(`第${index + 1}张图片上传失败:`, error);
  192. if (uploadedCount === totalCount) {
  193. that.uploading = false;
  194. uni.showToast({
  195. title: '部分图片上传失败',
  196. icon: 'none'
  197. });
  198. }
  199. }
  200. })
  201. // uni.uploadFile({
  202. // url: '你的上传接口地址',
  203. // filePath: filePath,
  204. // name: 'file',
  205. // formData: {
  206. // 'type': 'company_photo'
  207. // },
  208. // success: (uploadRes) => {
  209. // uploadedCount++;
  210. // const data = JSON.parse(uploadRes.data);
  211. // if (data.code === 200) {
  212. // that.imageList.push({
  213. // url: data.data.url
  214. // });
  215. // }
  216. // // 更新进度
  217. // that.uploadProgress = Math.floor((uploadedCount / totalCount) * 100);
  218. // // 所有图片上传完成
  219. // if (uploadedCount === totalCount) {
  220. // that.uploading = false;
  221. // uni.showToast({
  222. // title: `成功上传${uploadedCount}张图片`,
  223. // icon: 'success'
  224. // });
  225. // }
  226. // },
  227. // fail: (error) => {
  228. // uploadedCount++;
  229. // console.log(`第${index + 1}张图片上传失败:`, error);
  230. // if (uploadedCount === totalCount) {
  231. // that.uploading = false;
  232. // uni.showToast({
  233. // title: '部分图片上传失败',
  234. // icon: 'none'
  235. // });
  236. // }
  237. // }
  238. // });
  239. });
  240. },
  241. // 预览图片
  242. previewImage(index) {
  243. if (this.imageList.length > 0) {
  244. const urls = this.imageList.map(item => item.url);
  245. uni.previewImage({
  246. urls: urls,
  247. current: index,
  248. });
  249. }
  250. },
  251. // 删除图片
  252. deleteImage(index) {
  253. const that = this;
  254. uni.showModal({
  255. title: "提示",
  256. content: "确定要删除这张照片吗?",
  257. success: (res) => {
  258. if (res.confirm) {
  259. that.imageList.splice(index, 1);
  260. uni.showToast({
  261. title: "删除成功",
  262. icon: "success",
  263. });
  264. }
  265. },
  266. });
  267. },
  268. // 下一步
  269. goJobPostingSecond() {
  270. if (this.imageList.length === 0) {
  271. uni.showToast({
  272. title: "请上传公司照片",
  273. icon: "none",
  274. });
  275. return;
  276. }
  277. // 跳转到下一页,传递图片数据
  278. const imageUrls = this.imageList.map(item => item.url);
  279. const companyData = this.companyData
  280. companyData.photos=imageUrls.join(',')
  281. uni.navigateTo({
  282. url: "/my/renzheng/mainWorkIntro?companyData=" + encodeURIComponent(JSON.stringify(companyData)),
  283. });
  284. },
  285. },
  286. };
  287. </script>
  288. <style lang="scss" scoped>
  289. .switch-roles {
  290. background-color: #fff;
  291. position: absolute;
  292. left: 0;
  293. right: 0;
  294. top: 0;
  295. bottom: 0;
  296. display: flex;
  297. flex-direction: column;
  298. .roles-content {
  299. width: 100%;
  300. flex: 1;
  301. overflow: hidden;
  302. overflow-y: auto;
  303. .content {
  304. padding: 40rpx;
  305. box-sizing: border-box;
  306. display: flex;
  307. flex-direction: column;
  308. align-items: center;
  309. justify-content: center;
  310. .progress-num {
  311. color: #016bf6;
  312. font-family: DM Sans;
  313. font-size: 24rpx;
  314. font-weight: 500;
  315. width: 100%;
  316. padding-bottom: 20rpx;
  317. box-sizing: border-box;
  318. text {
  319. font-size: 48rpx;
  320. font-weight: 700;
  321. }
  322. }
  323. .title {
  324. color: #333;
  325. width: 100%;
  326. font-family: DM Sans;
  327. font-size: 48rpx;
  328. font-weight: 700;
  329. display: flex;
  330. justify-content: space-between;
  331. align-items: center;
  332. margin-bottom: 20rpx;
  333. }
  334. .desc {
  335. color: rgba(102, 102, 102, 1);
  336. width: 100%;
  337. font-family: DM Sans;
  338. font-size: 24rpx;
  339. font-weight: 400;
  340. line-height: 32rpx;
  341. letter-spacing: 0.5%;
  342. text-align: left;
  343. box-sizing: border-box;
  344. margin-bottom: 40rpx;
  345. }
  346. .content-index {
  347. width: 100%;
  348. .upload-section {
  349. margin-bottom: 20rpx;
  350. .images-grid {
  351. display: grid;
  352. grid-template-columns: repeat(4, 1fr);
  353. gap: 20rpx;
  354. margin-bottom: 20rpx;
  355. .image-item {
  356. width: 142rpx;
  357. height: 142rpx;
  358. border-radius: 8rpx;
  359. position: relative;
  360. overflow: hidden;
  361. .preview-image {
  362. width: 100%;
  363. height: 100%;
  364. }
  365. .image-mask {
  366. position: absolute;
  367. top: 0;
  368. left: 0;
  369. width: 100%;
  370. height: 100%;
  371. background: rgba(0, 0, 0, 0.3);
  372. display: flex;
  373. align-items: center;
  374. justify-content: center;
  375. opacity: 0;
  376. transition: opacity 0.3s;
  377. }
  378. .delete-btn {
  379. position: absolute;
  380. top: 8rpx;
  381. right: 8rpx;
  382. width: 30rpx;
  383. height: 30rpx;
  384. background: rgba(0, 0, 0, 0.5);
  385. border-radius: 50%;
  386. display: flex;
  387. align-items: center;
  388. justify-content: center;
  389. }
  390. &:active .image-mask {
  391. opacity: 1;
  392. }
  393. }
  394. .upload-box {
  395. width: 142rpx;
  396. height: 142rpx;
  397. border-radius: 8rpx;
  398. display: flex;
  399. align-items: center;
  400. justify-content: center;
  401. background: #eee;
  402. .upload-placeholder {
  403. display: flex;
  404. flex-direction: column;
  405. align-items: center;
  406. justify-content: center;
  407. .upload-text {
  408. color: #666;
  409. font-size: 20rpx;
  410. margin-top: 8rpx;
  411. font-family: DM Sans;
  412. }
  413. }
  414. }
  415. }
  416. .upload-count {
  417. color: #666;
  418. font-size: 24rpx;
  419. text-align: center;
  420. margin-bottom: 20rpx;
  421. }
  422. .upload-progress {
  423. display: flex;
  424. align-items: center;
  425. gap: 20rpx;
  426. .progress-bar {
  427. flex: 1;
  428. height: 8rpx;
  429. background: #f0f0f0;
  430. border-radius: 4rpx;
  431. overflow: hidden;
  432. .progress-inner {
  433. height: 100%;
  434. background: #016bf6;
  435. border-radius: 4rpx;
  436. transition: width 0.3s;
  437. }
  438. }
  439. .progress-text {
  440. color: #016bf6;
  441. font-size: 24rpx;
  442. min-width: 80rpx;
  443. }
  444. }
  445. }
  446. .warning-box {
  447. color: rgba(102, 102, 102, 1);
  448. font-family: DM Sans;
  449. font-size: 24rpx;
  450. font-weight: 400;
  451. line-height: 32rpx;
  452. .warning-item{
  453. margin-top: 8rpx;
  454. }
  455. }
  456. }
  457. }
  458. }
  459. .submit-btn {
  460. flex-shrink: 0;
  461. border-radius: 999px;
  462. background: #ff6600;
  463. color: rgba(255, 255, 255, 1);
  464. font-family: DM Sans;
  465. font-size: 32rpx;
  466. font-weight: 400;
  467. line-height: 48rpx;
  468. display: flex;
  469. justify-content: center;
  470. align-items: center;
  471. padding: 24rpx 32rpx;
  472. box-sizing: border-box;
  473. margin: 30rpx 40rpx;
  474. margin-top: 20rpx;
  475. &.disabled {
  476. background: #ccc;
  477. color: #999;
  478. }
  479. }
  480. }
  481. </style>