companyLogo.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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.text) {
  82. this.text = options.text;
  83. }
  84. },
  85. methods: {
  86. // 选择图片
  87. chooseImage() {
  88. const that = this;
  89. uni.chooseImage({
  90. count: 1,
  91. sizeType: ["compressed"], // 可以指定是原图还是压缩图,默认二者都有
  92. sourceType: ["album", "camera"], // 可以指定来源是相册还是相机,默认二者都有
  93. success: (res) => {
  94. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  95. const tempFilePaths = res.tempFilePaths;
  96. // 这里可以添加图片验证
  97. that.validateAndUploadImage(tempFilePaths[0]);
  98. },
  99. fail: (error) => {
  100. console.log("选择图片失败:", error);
  101. uni.showToast({
  102. title: "选择图片失败",
  103. icon: "none",
  104. });
  105. },
  106. });
  107. },
  108. // 验证并上传图片
  109. validateAndUploadImage(tempFilePath) {
  110. const that = this;
  111. // 获取图片信息
  112. uni.getImageInfo({
  113. src: tempFilePath,
  114. success: (imageInfo) => {
  115. console.log("图片信息:", imageInfo);
  116. // 这里可以添加图片尺寸验证
  117. // if (imageInfo.width < 100 || imageInfo.height < 100) {
  118. // uni.showToast({
  119. // title: '图片尺寸过小,建议200×200px以上',
  120. // icon: 'none'
  121. // });
  122. // return;
  123. // }
  124. // 开始上传
  125. that.uploadImage(tempFilePath);
  126. },
  127. fail: (error) => {
  128. console.log("获取图片信息失败:", error);
  129. that.uploadImage(tempFilePath); // 即使获取信息失败也继续上传
  130. },
  131. });
  132. },
  133. // 上传图片到服务器
  134. uploadImage(filePath) {
  135. const that = this;
  136. that.uploading = true;
  137. that.uploadProgress = 0;
  138. // 模拟上传进度
  139. const progressTimer = setInterval(() => {
  140. that.uploadProgress += 10;
  141. if (that.uploadProgress >= 90) {
  142. clearInterval(progressTimer);
  143. }
  144. }, 100);
  145. // 这里替换为你的实际上传接口
  146. // uni.uploadFile({
  147. // url: '你的上传接口地址',
  148. // filePath: filePath,
  149. // name: 'file',
  150. // formData: {
  151. // 'type': 'company_logo'
  152. // },
  153. // success: (uploadRes) => {
  154. // clearInterval(progressTimer);
  155. // that.uploadProgress = 100;
  156. //
  157. // const data = JSON.parse(uploadRes.data);
  158. // if (data.code === 200) {
  159. // that.logoImage = data.data.url;
  160. // uni.showToast({
  161. // title: '上传成功',
  162. // icon: 'success'
  163. // });
  164. // } else {
  165. // uni.showToast({
  166. // title: data.message || '上传失败',
  167. // icon: 'none'
  168. // });
  169. // }
  170. //
  171. // setTimeout(() => {
  172. // that.uploading = false;
  173. // }, 500);
  174. // },
  175. // fail: (error) => {
  176. // clearInterval(progressTimer);
  177. // that.uploading = false;
  178. // uni.showToast({
  179. // title: '上传失败',
  180. // icon: 'none'
  181. // });
  182. // }
  183. // });
  184. // 模拟上传成功(实际开发中请使用上面的上传代码)
  185. setTimeout(() => {
  186. clearInterval(progressTimer);
  187. that.uploadProgress = 100;
  188. that.logoImage = filePath; // 使用本地路径,实际开发中应该使用服务器返回的URL
  189. setTimeout(() => {
  190. that.uploading = false;
  191. uni.showToast({
  192. title: "上传成功",
  193. icon: "success",
  194. });
  195. }, 500);
  196. }, 1500);
  197. },
  198. // 预览图片
  199. previewImage() {
  200. if (this.logoImage) {
  201. uni.previewImage({
  202. urls: [this.logoImage],
  203. current: 0,
  204. });
  205. }
  206. },
  207. // 删除图片
  208. deleteImage() {
  209. const that = this;
  210. uni.showModal({
  211. title: "提示",
  212. content: "确定要删除这个LOGO吗?",
  213. success: (res) => {
  214. if (res.confirm) {
  215. that.logoImage = "";
  216. that.uploadProgress = 0;
  217. }
  218. },
  219. });
  220. },
  221. goJobPostingSecond() {
  222. if (!this.logoImage) {
  223. uni.showToast({
  224. title: "请上传公司LOGO",
  225. icon: "none",
  226. });
  227. return;
  228. }
  229. uni.navigateTo({
  230. url: "/my/renzheng/companyImg?logo=" + encodeURIComponent(this.logoImage),
  231. });
  232. },
  233. },
  234. };
  235. </script>
  236. <style lang="scss" scoped>
  237. .switch-roles {
  238. background-color: #fff;
  239. position: absolute;
  240. left: 0;
  241. right: 0;
  242. top: 0;
  243. bottom: 0;
  244. display: flex;
  245. flex-direction: column;
  246. .roles-content {
  247. width: 100%;
  248. flex: 1;
  249. overflow: hidden;
  250. overflow-y: auto;
  251. .content {
  252. padding: 40rpx;
  253. box-sizing: border-box;
  254. display: flex;
  255. flex-direction: column;
  256. align-items: center;
  257. justify-content: center;
  258. .progress-num {
  259. color: #016bf6;
  260. font-family: DM Sans;
  261. font-size: 24rpx;
  262. font-weight: 500;
  263. width: 100%;
  264. padding-bottom: 20rpx;
  265. box-sizing: border-box;
  266. text {
  267. font-size: 48rpx;
  268. font-weight: 700;
  269. }
  270. }
  271. .title {
  272. color: #333;
  273. width: 100%;
  274. font-family: DM Sans;
  275. font-size: 48rpx;
  276. font-weight: 700;
  277. display: flex;
  278. justify-content: space-between;
  279. align-items: center;
  280. margin-bottom: 20rpx;
  281. }
  282. .desc {
  283. color: rgba(102, 102, 102, 1);
  284. width: 100%;
  285. font-family: DM Sans;
  286. font-size: 24rpx;
  287. font-weight: 400;
  288. line-height: 32rpx;
  289. letter-spacing: 0.5%;
  290. text-align: left;
  291. box-sizing: border-box;
  292. margin-bottom: 40rpx;
  293. }
  294. .content-index {
  295. width: 100%;
  296. .upload-section {
  297. margin-bottom: 20rpx;
  298. .upload-box {
  299. width: 142rpx;
  300. height: 142rpx;
  301. border-radius: 8rpx;
  302. display: flex;
  303. align-items: center;
  304. justify-content: center;
  305. background: #eee;
  306. position: relative;
  307. overflow: hidden;
  308. &.has-image {
  309. border-style: solid;
  310. border-color: #016bf6;
  311. }
  312. .upload-placeholder {
  313. display: flex;
  314. flex-direction: column;
  315. align-items: center;
  316. justify-content: center;
  317. .upload-text {
  318. color: #666;
  319. font-size: 20rpx;
  320. margin-top: 8rpx;
  321. font-family: DM Sans;
  322. }
  323. .upload-subtext {
  324. color: #999;
  325. font-size: 20rpx;
  326. }
  327. }
  328. .image-preview {
  329. width: 100%;
  330. height: 100%;
  331. position: relative;
  332. .preview-image {
  333. width: 100%;
  334. height: 100%;
  335. border-radius: 12rpx;
  336. }
  337. .image-mask {
  338. position: absolute;
  339. top: 0;
  340. left: 0;
  341. width: 100%;
  342. height: 100%;
  343. background: rgba(0, 0, 0, 0.5);
  344. display: flex;
  345. align-items: center;
  346. justify-content: center;
  347. opacity: 0;
  348. transition: opacity 0.3s;
  349. &:active {
  350. opacity: 1;
  351. }
  352. }
  353. .delete-btn {
  354. position: absolute;
  355. top: 8rpx;
  356. right: 8rpx;
  357. width: 30rpx;
  358. height: 30rpx;
  359. background: rgba(0, 0, 0, 0.5);
  360. border-radius: 50%;
  361. display: flex;
  362. align-items: center;
  363. justify-content: center;
  364. }
  365. &:active .image-mask {
  366. opacity: 1;
  367. }
  368. }
  369. }
  370. .upload-progress {
  371. margin-top: 20rpx;
  372. display: flex;
  373. align-items: center;
  374. gap: 20rpx;
  375. .progress-bar {
  376. flex: 1;
  377. height: 8rpx;
  378. background: #f0f0f0;
  379. border-radius: 4rpx;
  380. overflow: hidden;
  381. .progress-inner {
  382. height: 100%;
  383. background: #016bf6;
  384. border-radius: 4rpx;
  385. transition: width 0.3s;
  386. }
  387. }
  388. .progress-text {
  389. color: #016bf6;
  390. font-size: 24rpx;
  391. min-width: 80rpx;
  392. }
  393. }
  394. }
  395. .warning-box {
  396. color: rgba(102, 102, 102, 1);
  397. font-family: DM Sans;
  398. font-size: 24rpx;
  399. font-weight: 400;
  400. line-height: 32rpx;
  401. .warning-item {
  402. margin-top: 8rpx;
  403. }
  404. }
  405. }
  406. }
  407. }
  408. .submit-btn {
  409. flex-shrink: 0;
  410. border-radius: 999px;
  411. background: #ff6600;
  412. color: rgba(255, 255, 255, 1);
  413. font-family: DM Sans;
  414. font-size: 32rpx;
  415. font-weight: 400;
  416. line-height: 48rpx;
  417. display: flex;
  418. justify-content: center;
  419. align-items: center;
  420. padding: 24rpx 32rpx;
  421. box-sizing: border-box;
  422. margin: 30rpx 40rpx;
  423. margin-top: 20rpx;
  424. &.disabled {
  425. background: #ccc;
  426. color: #999;
  427. }
  428. }
  429. }
  430. </style>