index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <!-- 校验是否完善人才必填信息 -->
  2. <template>
  3. <scroll-view class="scrollBox" scroll-y="true">
  4. <view class="content">
  5. <view class="text-center font-size-20 color-primary MiSans-Medium" :class="{'ss-m-b-50': !wxLoginCode}">请完善您的基本信息</view>
  6. <view v-if="wxLoginCode" class="font-size-14 color-666 ss-m-b-50 ss-m-t-10 text-center">扫码登录网页时,需完善信息后方可授权成功!</view>
  7. <uni-forms
  8. ref="baseInfoRef"
  9. v-model="formData"
  10. :rules="formRules"
  11. validateTrigger="bind"
  12. label-width="86px"
  13. labelAlign="center"
  14. >
  15. <uni-forms-item label="头像" name="avatar" class="f-straight" required>
  16. <view style="display: flex;flex-wrap: wrap;">
  17. <view class="upload-img" v-if="formData?.avatar">
  18. <uni-icons size="35" type="clear" color="#fe574a" style="position: absolute;right: -15px; top: -15px; z-index: 9" @click="formData.avatar = ''"></uni-icons>
  19. <image :src="formData?.avatar" mode="contain" style="width: 200rpx;height: 200rpx;" @click="handlePreviewImage"></image>
  20. </view>
  21. <view v-else class="upload-file" @click="uploadPhotos">
  22. <uni-icons type="plusempty" size="50" color="#f1f1f1"></uni-icons>
  23. </view>
  24. </view>
  25. </uni-forms-item>
  26. <uni-forms-item name="name" label="姓名" required>
  27. <uni-easyinput placeholder="请输入姓名" v-model="formData.name" :inputBorder="false" type="text"></uni-easyinput>
  28. </uni-forms-item>
  29. <uni-forms-item name="sex" label="性别" required>
  30. <uni-data-picker v-model="formData.sex" :localdata="dictObj.sex" :clear-icon="false" popup-title="请选择性别" :map="{ text: 'label', value: 'value' }"></uni-data-picker>
  31. </uni-forms-item>
  32. <uni-forms-item name="phone" label="联系电话" required>
  33. <uni-easyinput placeholder="请输入联系电话" v-model="formData.phone" :inputBorder="false" type="number"></uni-easyinput>
  34. </uni-forms-item>
  35. <uni-forms-item name="email" label="常用邮箱" required>
  36. <uni-easyinput v-model="formData.email" placeholder="请输入常用邮箱" />
  37. </uni-forms-item>
  38. <uni-forms-item required label="出生日期" name="birthday">
  39. <uni-datetime-picker type="date" return-type="timestamp" v-model="formData.birthday" />
  40. </uni-forms-item>
  41. <uni-forms-item name="enterpriseName" label="任职企业名称" required>
  42. <uni-easyinput placeholder="请填写任职企业名称(可填暂无)" v-model="formData.enterpriseName" :clear-icon="true" type="text"></uni-easyinput>
  43. </uni-forms-item>
  44. <uni-forms-item name="positionName" label="任职职位名称" required>
  45. <uni-easyinput placeholder="请填写任职职位名称(可填暂无)" v-model="formData.positionName" :clear-icon="true" type="text"></uni-easyinput>
  46. </uni-forms-item>
  47. <uni-forms-item name="interestedPositionId" label="意向职位" required>
  48. <uni-data-picker v-model="formData.interestedPositionId" :localdata="dictObj.positionSecondData" :clear-icon="false" popup-title="请选择意向职位" :map="{ text: 'nameCn', value: 'id' }"></uni-data-picker>
  49. </uni-forms-item>
  50. <uni-forms-item name="jobStatus" label="求职状态" required>
  51. <uni-data-picker v-model="formData.jobStatus" :localdata="dictObj.jobStatus" :clear-icon="false" popup-title="请选择求职状态" :map="{ text: 'label', value: 'value' }"></uni-data-picker>
  52. </uni-forms-item>
  53. <uni-forms-item name="expType" label="工作经验" required>
  54. <uni-data-picker v-model="formData.expType" :localdata="dictObj.exp" :clear-icon="false" popup-title="请选择工作经验" :clear="false" :map="{ text: 'label', value: 'value' }"></uni-data-picker>
  55. </uni-forms-item>
  56. <uni-forms-item name="eduType" label="最高学历" required>
  57. <uni-data-picker v-model="formData.eduType" :localdata="dictObj.edu" :clear-icon="false" popup-title="请选择最高学历" :clear="false" :map="{ text: 'label', value: 'value' }"></uni-data-picker>
  58. </uni-forms-item>
  59. </uni-forms>
  60. <view class="f-horizon-center">
  61. <button type="primary" size="default" class="send-button" @click="submit">提 交</button>
  62. </view>
  63. <view class="f-horizon-center">
  64. <view class="changeRole" @tap="handleLogout">切换账号</view>
  65. </view>
  66. </view>
  67. <uni-popup ref="logoutPopup" type="dialog">
  68. <uni-popup-dialog type="warn" cancelText="取消" confirmText="确定" title="系统提示" content="确认退出账号?" @confirm="handleLogoutConfirm" @close="handleLogoutClose">
  69. </uni-popup-dialog>
  70. </uni-popup>
  71. </scroll-view>
  72. </template>
  73. <script setup>
  74. import { ref, unref, onMounted, nextTick } from 'vue'
  75. import { mobile, emailRequired } from '@/utils/validate'
  76. import { dictObj } from '@/utils/position.js'
  77. import { savePersonSimpleInfo } from '@/api/user'
  78. import { showAuthModal } from '@/hooks/useModal'
  79. import { userStore } from '@/store/user'; const useUserStore = userStore()
  80. import { uploadFile } from '@/api/file'
  81. import { weixinLoginAuthorize } from '@/api/qrcodeLogin.js'
  82. const wxLoginCode = uni.getStorageSync('wxLoginCode')
  83. const baseInfoRef = ref()
  84. const formData = ref({ // 必填项目
  85. name: null,
  86. sex: null,
  87. phone: null,
  88. email: null,
  89. birthday: '1990-01-01',
  90. enterpriseName: null,
  91. positionName: null,
  92. interestedPositionId: null,
  93. jobStatus: null,
  94. expType: null,
  95. eduType: null,
  96. })
  97. onMounted(() => {
  98. nextTick(() => {
  99. const baseInfo = useUserStore?.baseInfo || null
  100. if (baseInfo && Object.keys(baseInfo).length) {
  101. Object.keys(formData.value).forEach(key => {
  102. formData.value[key] = baseInfo[key] || baseInfo[key] === 0 ? baseInfo[key] : formData.value[key] ? formData.value[key] : null
  103. })
  104. }
  105. if (!formData.value.phone && useUserStore?.phone) formData.value.phone = useUserStore.phone
  106. })
  107. })
  108. const formRules = {
  109. avatar:{
  110. rules: [{required: true, errorMessage: '请上传头像' }]
  111. },
  112. name:{
  113. rules: [{required: true, errorMessage: '请输入姓名' }]
  114. },
  115. sex : {
  116. rules: [{required: true, errorMessage: '请选择您的性别' }]
  117. },
  118. phone: mobile,
  119. birthday:{
  120. rules: [{required: true, errorMessage: '请选择您的出生日期' }]
  121. },
  122. enterpriseName:{
  123. rules: [{required: true, errorMessage: '请填写任职企业名称(可填暂无)' }]
  124. },
  125. positionName:{
  126. rules: [{required: true, errorMessage: '请填写任职职位名称(可填暂无)' }]
  127. },
  128. email: emailRequired,
  129. expType: {
  130. rules: [{required: true, errorMessage: '请选择您的工作年限' }]
  131. },
  132. eduType: {
  133. rules: [{required: true, errorMessage: '请选择您的最高学历' }]
  134. },
  135. jobStatus: {
  136. rules: [{required: true, errorMessage: '请选择您的求职状态' }]
  137. }
  138. }
  139. const logoutPopup = ref()
  140. // 退出登录
  141. const handleLogout = () => {
  142. logoutPopup.value.open()
  143. }
  144. const handleLogoutClose = () => {
  145. logoutPopup.value.close()
  146. }
  147. const handleLogoutConfirm = async () => {
  148. await useUserStore.handleLogout()
  149. showAuthModal()
  150. }
  151. // 图片预览
  152. const handlePreviewImage = () => {
  153. uni.previewImage({
  154. current: 0,
  155. urls: [formData.value.avatar]
  156. })
  157. }
  158. // 选择头像
  159. const uploadPhotos = () => {
  160. wx.chooseImage({
  161. count: 1,
  162. sizeType: ['original', 'compressed'],
  163. sourceType: ['album', 'camera'],
  164. success: function(res){
  165. const size = res.tempFiles[0]?.size || 0
  166. if (size >= 31457280) {
  167. uni.showToast({
  168. icon: 'none',
  169. title: '头像上传大小不得超过 20MB !',
  170. duration: 2000
  171. })
  172. return
  173. }
  174. const path = res.tempFilePaths[0]
  175. uploadFile(path, 'img').then(res => {
  176. formData.value.avatar = res.data
  177. }).catch(error => {
  178. uni.showToast({
  179. icon: 'error',
  180. title: '图片上传失败!',
  181. duration: 2000
  182. })
  183. })
  184. }
  185. })
  186. }
  187. const dealQuery = () => {
  188. const interestedList = [{ positionId: formData.value.interestedPositionId || null }]
  189. const workExpList = [{
  190. enterpriseName: formData.value.enterpriseName || null,
  191. positionName: formData.value.positionName || null,
  192. }]
  193. return { ...formData.value, interestedList, workExpList }
  194. }
  195. const handleRemove = () => {
  196. uni.removeStorageSync('wxLoginCode')
  197. setTimeout(() => {
  198. uni.switchTab({
  199. url: '/pages/index/my'
  200. })
  201. }, 2000)
  202. }
  203. // 微信扫码登录授权给pc
  204. const handleWeiXinQrCodeAuthorize = async () => {
  205. if (!uni.getStorageSync('wxLoginCode')) {
  206. return uni.showToast({ title: '请重新扫码进行授权', icon: 'none', duration: 2000 })
  207. }
  208. try {
  209. await weixinLoginAuthorize({ uuid: uni.getStorageSync('wxLoginCode') })
  210. uni.showToast({ title: '授权网页登录成功', duration: 2000, icon: 'none' })
  211. handleRemove()
  212. } catch (error) {
  213. console.log(error, '授权接口error');
  214. handleRemove()
  215. }
  216. }
  217. const submit = async () => {
  218. const validate = await unref(baseInfoRef).validate()
  219. if (!validate) return uni.showToast({ title: '请将信息补充完整', icon: 'none' })
  220. try {
  221. const query = dealQuery()
  222. await savePersonSimpleInfo(query)
  223. uni.showToast({ title: '保存成功', icon: 'none' })
  224. await useUserStore.getInfo()
  225. // await useUserStore.getUserInfo()
  226. // 若是扫码登录且账号未注册的,注册后需授权给pc登录
  227. if (wxLoginCode) handleWeiXinQrCodeAuthorize()
  228. } catch (err) {
  229. uni.showToast({ title: err?.msg || '保存失败', icon: 'none' })
  230. }
  231. }
  232. </script>
  233. <style lang="scss" scoped>
  234. .scrollBox {
  235. width: 100vw;
  236. // height: 100vh;
  237. height: calc(100vh - 30rpx);
  238. margin-bottom: 30rpx;
  239. }
  240. .content {
  241. padding: 30rpx;
  242. }
  243. .changeRole {
  244. color: var(--color-666);
  245. font-size: 15px;
  246. line-height: 26px;
  247. margin-bottom: 40rpx;
  248. }
  249. .upload-img{
  250. position: relative;
  251. width: 200rpx;
  252. height: 200rpx;
  253. border: 1px solid #f1f1f1;
  254. margin: 10rpx;
  255. }
  256. .upload-file{
  257. width: 200rpx;
  258. height: 200rpx;
  259. border: 1px solid #f1f1f1;
  260. margin: 10rpx;
  261. display: flex;
  262. justify-content: center;
  263. align-items: center;
  264. border-radius: 10rpx;
  265. }
  266. </style>