companyLogo.vue 11 KB

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