companyLogo.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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>6</text>/8 </view>
  7. <view class="title">
  8. <view>添加公司LOGO</view>
  9. </view>
  10. <view class="desc">该logo将出现在公司主页及公司下展示的所有职位上</view>
  11. <view class="content-index">
  12. <!-- Logo上传区域 -->
  13. <view class="upload-section">
  14. <view
  15. class="upload-box"
  16. :class="{ 'has-image': logoImage }"
  17. @click="chooseImage"
  18. >
  19. <view v-if="!logoImage" class="upload-placeholder">
  20. <u-icon name="plus" color="#999" size="40"></u-icon>
  21. <text class="upload-text">添加照片</text>
  22. </view>
  23. <view v-else class="image-preview">
  24. <image :src="logoImage" mode="aspectFill" class="preview-image"></image>
  25. <view class="image-mask" @click.stop="previewImage">
  26. <u-icon name="eye" color="#fff" size="40"></u-icon>
  27. </view>
  28. <view class="delete-btn" @click.stop="deleteImage">
  29. <u-icon name="close" color="#fff" size="20"></u-icon>
  30. </view>
  31. </view>
  32. </view>
  33. <!-- 上传进度 -->
  34. <view v-if="uploading" class="upload-progress">
  35. <view class="progress-bar">
  36. <view
  37. class="progress-inner"
  38. :style="{ width: uploadProgress + '%' }"
  39. ></view>
  40. </view>
  41. <text class="progress-text">{{ uploadProgress }}%</text>
  42. </view>
  43. </view>
  44. <!-- 注意事项 -->
  45. <view class="warning-box">
  46. <view class="warning-title">注意事项:</view>
  47. <view class="warning-list">
  48. <view class="warning-item">1. 请上传清晰且完整的图片</view>
  49. <view class="warning-item"
  50. >2.
  51. 请上传品牌相关的图片,含有其他内容将无法通过审核(包括但不限于含有水印、招聘信息、联系方式、二维码等相关内容)</view
  52. >
  53. <view class="warning-item"
  54. >3. 上传图片须符合中国相关法律法规,不得含有违法内容或不良信息</view
  55. >
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <view class="submit-btn" :class="{ disabled: !logoImage }" @click="goJobPostingSecond"
  62. >下一步</view
  63. >
  64. </view>
  65. </template>
  66. <script>
  67. import navBar from "@/components/nav-bar/index.vue";
  68. export default {
  69. data() {
  70. return {
  71. text: "",
  72. logoImage: "", // 上传的logo图片URL
  73. uploading: false, // 是否正在上传
  74. uploadProgress: 0, // 上传进度
  75. };
  76. },
  77. components: {
  78. navBar,
  79. },
  80. onLoad(options) {
  81. if (options.companyData) {
  82. this.companyData = JSON.parse(options.companyData);
  83. console.log(this.companyData);
  84. }
  85. },
  86. methods: {
  87. // 选择图片
  88. async chooseImage() {
  89. const that = this;
  90. // 1. 先判断系统类型,区分Android/iOS权限
  91. const systemInfo = uni.getSystemInfoSync();
  92. const isAndroid = systemInfo.system.includes('Android');
  93. const permissionType = isAndroid ? 'storage' : 'photos'; // Android=存储,iOS=相册
  94. // 2. 权限检查(复用之前封装的 checkPermission 函数)
  95. const hasPermission = this.$queue.checkPermission(
  96. permissionType,
  97. isAndroid
  98. ? '选择/拍摄照片需要相机/相册权限,用于上传企业logo/企业资料' // Android 专属提示
  99. : '选择/拍摄照片需要相机/相册权限,用于上传企业logo/企业资料'
  100. );
  101. if (!hasPermission) {
  102. uni.showToast({ title: '未获取权限,无法选择照片', icon: 'none' });
  103. return;
  104. }
  105. uni.chooseImage({
  106. count: 1,
  107. sizeType: ["compressed"], // 可以指定是原图还是压缩图,默认二者都有
  108. sourceType: ["album", "camera"], // 可以指定来源是相册还是相机,默认二者都有
  109. success: (res) => {
  110. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  111. const tempFilePaths = res.tempFilePaths;
  112. // 这里可以添加图片验证
  113. that.validateAndUploadImage(tempFilePaths[0]);
  114. },
  115. fail: (error) => {
  116. console.log("选择图片失败:", error);
  117. uni.showToast({
  118. title: "选择图片失败",
  119. icon: "none",
  120. });
  121. },
  122. });
  123. },
  124. // 验证并上传图片
  125. validateAndUploadImage(tempFilePath) {
  126. const that = this;
  127. // 获取图片信息
  128. uni.getImageInfo({
  129. src: tempFilePath,
  130. success: (imageInfo) => {
  131. console.log("图片信息:", imageInfo);
  132. // 这里可以添加图片尺寸验证
  133. // if (imageInfo.width < 100 || imageInfo.height < 100) {
  134. // uni.showToast({
  135. // title: '图片尺寸过小,建议200×200px以上',
  136. // icon: 'none'
  137. // });
  138. // return;
  139. // }
  140. // 开始上传
  141. that.uploadImage(tempFilePath);
  142. },
  143. fail: (error) => {
  144. console.log("获取图片信息失败:", error);
  145. that.uploadImage(tempFilePath); // 即使获取信息失败也继续上传
  146. },
  147. });
  148. },
  149. // 上传图片到服务器
  150. uploadImage(filePath) {
  151. const that = this;
  152. that.uploading = true;
  153. that.uploadProgress = 0;
  154. // 模拟上传进度
  155. const progressTimer = setInterval(() => {
  156. that.uploadProgress += 10;
  157. if (that.uploadProgress >= 90) {
  158. clearInterval(progressTimer);
  159. }
  160. }, 100);
  161. this.$queue.uploadFile(filePath,(path)=>{
  162. if(path) {
  163. clearInterval(progressTimer);
  164. that.uploadProgress = 100;
  165. that.logoImage = path
  166. uni.showToast({
  167. title: '上传成功',
  168. icon: 'success'
  169. });
  170. }
  171. else {
  172. uni.showToast({
  173. title: data.message || '上传失败',
  174. icon: 'none'
  175. });
  176. }
  177. setTimeout(() => {
  178. that.uploading = false;
  179. }, 500);
  180. })
  181. // 这里替换为你的实际上传接口
  182. // uni.uploadFile({
  183. // url: '你的上传接口地址',
  184. // filePath: filePath,
  185. // name: 'file',
  186. // formData: {
  187. // 'type': 'company_logo'
  188. // },
  189. // success: (uploadRes) => {
  190. // clearInterval(progressTimer);
  191. // that.uploadProgress = 100;
  192. //
  193. // const data = JSON.parse(uploadRes.data);
  194. // if (data.code === 200) {
  195. // that.logoImage = data.data.url;
  196. // uni.showToast({
  197. // title: '上传成功',
  198. // icon: 'success'
  199. // });
  200. // } else {
  201. // uni.showToast({
  202. // title: data.message || '上传失败',
  203. // icon: 'none'
  204. // });
  205. // }
  206. //
  207. // setTimeout(() => {
  208. // that.uploading = false;
  209. // }, 500);
  210. // },
  211. // fail: (error) => {
  212. // clearInterval(progressTimer);
  213. // that.uploading = false;
  214. // uni.showToast({
  215. // title: '上传失败',
  216. // icon: 'none'
  217. // });
  218. // }
  219. // });
  220. // 模拟上传成功(实际开发中请使用上面的上传代码)
  221. // setTimeout(() => {
  222. // clearInterval(progressTimer);
  223. // that.uploadProgress = 100;
  224. // that.logoImage = filePath; // 使用本地路径,实际开发中应该使用服务器返回的URL
  225. // setTimeout(() => {
  226. // that.uploading = false;
  227. // uni.showToast({
  228. // title: "上传成功",
  229. // icon: "success",
  230. // });
  231. // }, 500);
  232. // }, 1500);
  233. },
  234. // 预览图片
  235. previewImage() {
  236. if (this.logoImage) {
  237. uni.previewImage({
  238. urls: [this.logoImage],
  239. current: 0,
  240. });
  241. }
  242. },
  243. // 删除图片
  244. deleteImage() {
  245. const that = this;
  246. uni.showModal({
  247. title: "提示",
  248. content: "确定要删除这个LOGO吗?",
  249. success: (res) => {
  250. if (res.confirm) {
  251. that.logoImage = "";
  252. that.uploadProgress = 0;
  253. }
  254. },
  255. });
  256. },
  257. goJobPostingSecond() {
  258. if (!this.logoImage) {
  259. uni.showToast({
  260. title: "请上传公司LOGO",
  261. icon: "none",
  262. });
  263. return;
  264. }
  265. const companyData = this.companyData
  266. companyData.companyLogo = this.logoImage
  267. uni.navigateTo({
  268. url: "/my/renzheng/companyImg?companyData=" + encodeURIComponent(JSON.stringify(companyData)),
  269. });
  270. },
  271. },
  272. };
  273. </script>
  274. <style lang="scss" scoped>
  275. .switch-roles {
  276. background-color: #fff;
  277. position: absolute;
  278. left: 0;
  279. right: 0;
  280. top: 0;
  281. bottom: 0;
  282. display: flex;
  283. flex-direction: column;
  284. .roles-content {
  285. width: 100%;
  286. flex: 1;
  287. overflow: hidden;
  288. overflow-y: auto;
  289. .content {
  290. padding: 40rpx;
  291. box-sizing: border-box;
  292. display: flex;
  293. flex-direction: column;
  294. align-items: center;
  295. justify-content: center;
  296. .progress-num {
  297. color: #016bf6;
  298. font-family: DM Sans;
  299. font-size: 24rpx;
  300. font-weight: 500;
  301. width: 100%;
  302. padding-bottom: 20rpx;
  303. box-sizing: border-box;
  304. text {
  305. font-size: 48rpx;
  306. font-weight: 700;
  307. }
  308. }
  309. .title {
  310. color: #333;
  311. width: 100%;
  312. font-family: DM Sans;
  313. font-size: 48rpx;
  314. font-weight: 700;
  315. display: flex;
  316. justify-content: space-between;
  317. align-items: center;
  318. margin-bottom: 20rpx;
  319. }
  320. .desc {
  321. color: rgba(102, 102, 102, 1);
  322. width: 100%;
  323. font-family: DM Sans;
  324. font-size: 24rpx;
  325. font-weight: 400;
  326. line-height: 32rpx;
  327. letter-spacing: 0.5%;
  328. text-align: left;
  329. box-sizing: border-box;
  330. margin-bottom: 40rpx;
  331. }
  332. .content-index {
  333. width: 100%;
  334. .upload-section {
  335. margin-bottom: 20rpx;
  336. .upload-box {
  337. width: 142rpx;
  338. height: 142rpx;
  339. border-radius: 8rpx;
  340. display: flex;
  341. align-items: center;
  342. justify-content: center;
  343. background: #eee;
  344. position: relative;
  345. overflow: hidden;
  346. &.has-image {
  347. border-style: solid;
  348. border-color: #016bf6;
  349. }
  350. .upload-placeholder {
  351. display: flex;
  352. flex-direction: column;
  353. align-items: center;
  354. justify-content: center;
  355. .upload-text {
  356. color: #666;
  357. font-size: 20rpx;
  358. margin-top: 8rpx;
  359. font-family: DM Sans;
  360. }
  361. .upload-subtext {
  362. color: #999;
  363. font-size: 20rpx;
  364. }
  365. }
  366. .image-preview {
  367. width: 100%;
  368. height: 100%;
  369. position: relative;
  370. .preview-image {
  371. width: 100%;
  372. height: 100%;
  373. border-radius: 12rpx;
  374. }
  375. .image-mask {
  376. position: absolute;
  377. top: 0;
  378. left: 0;
  379. width: 100%;
  380. height: 100%;
  381. background: rgba(0, 0, 0, 0.5);
  382. display: flex;
  383. align-items: center;
  384. justify-content: center;
  385. opacity: 0;
  386. transition: opacity 0.3s;
  387. &:active {
  388. opacity: 1;
  389. }
  390. }
  391. .delete-btn {
  392. position: absolute;
  393. top: 8rpx;
  394. right: 8rpx;
  395. width: 30rpx;
  396. height: 30rpx;
  397. background: rgba(0, 0, 0, 0.5);
  398. border-radius: 50%;
  399. display: flex;
  400. align-items: center;
  401. justify-content: center;
  402. }
  403. &:active .image-mask {
  404. opacity: 1;
  405. }
  406. }
  407. }
  408. .upload-progress {
  409. margin-top: 20rpx;
  410. display: flex;
  411. align-items: center;
  412. gap: 20rpx;
  413. .progress-bar {
  414. flex: 1;
  415. height: 8rpx;
  416. background: #f0f0f0;
  417. border-radius: 4rpx;
  418. overflow: hidden;
  419. .progress-inner {
  420. height: 100%;
  421. background: #016bf6;
  422. border-radius: 4rpx;
  423. transition: width 0.3s;
  424. }
  425. }
  426. .progress-text {
  427. color: #016bf6;
  428. font-size: 24rpx;
  429. min-width: 80rpx;
  430. }
  431. }
  432. }
  433. .warning-box {
  434. color: rgba(102, 102, 102, 1);
  435. font-family: DM Sans;
  436. font-size: 24rpx;
  437. font-weight: 400;
  438. line-height: 32rpx;
  439. .warning-item {
  440. margin-top: 8rpx;
  441. }
  442. }
  443. }
  444. }
  445. }
  446. .submit-btn {
  447. flex-shrink: 0;
  448. border-radius: 999px;
  449. background: #ff6600;
  450. color: rgba(255, 255, 255, 1);
  451. font-family: DM Sans;
  452. font-size: 32rpx;
  453. font-weight: 400;
  454. line-height: 48rpx;
  455. display: flex;
  456. justify-content: center;
  457. align-items: center;
  458. padding: 24rpx 32rpx;
  459. box-sizing: border-box;
  460. margin: 30rpx 40rpx;
  461. margin-top: 20rpx;
  462. &.disabled {
  463. background: #ccc;
  464. color: #999;
  465. }
  466. }
  467. }
  468. </style>