index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <!-- 个人信息 -->
  3. <view>
  4. <!-- 头像区域 -->
  5. <view class="avatar-region">
  6. <view class="flex-items">
  7. <view class="font32 mar-l-20">
  8. 头像
  9. </view>
  10. <view class="mar-l-auto mar-r-20">
  11. <u-upload :fileList="fileList" @afterRead="afterRead" name="1" :maxCount="1">
  12. <view class="flex-items">
  13. <image class="avatar" :src="user.avatar||'../../static/images/avatar.png'"
  14. mode="aspectFill">
  15. </image>
  16. <uni-icons color="#d0d7df" type="right" size="30"></uni-icons>
  17. </view>
  18. </u-upload>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 基本信息区域 -->
  23. <view class="info-region">
  24. <view class="font-gray mar-l-20 mar-b-30">
  25. 基本信息
  26. </view>
  27. <view class="flex-items mar-b-50">
  28. <view class="font32 mar-l-20">
  29. 姓名
  30. </view>
  31. <view class="mar-l-auto mar-r-20">
  32. <view class="flex-items">
  33. <u-input v-model="user.account" :border="false" placeholder="请输入姓名"></u-input>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="flex-items mar-b-50">
  38. <view class="font32 mar-l-20 ">
  39. 手机号码
  40. </view>
  41. <view class="mar-l-auto mar-r-20">
  42. <view class="flex-items">
  43. <u-input v-model="user.phone" :border="false" placeholder="请输入手机号码" type="number"></u-input>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="flex-items mar-b-50">
  48. <view class="font32 mar-l-20 ">
  49. 公司名称
  50. </view>
  51. <view class="mar-l-auto mar-r-20 select-container">
  52. <view class="flex-items">
  53. <uni-data-select v-model="user.companyId" :localdata="companyOptions" :clear="false"
  54. class="custom-select"></uni-data-select>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="flex-items mar-b-50">
  59. <view class="font32 mar-l-20 ">
  60. 部门
  61. </view>
  62. <view class="mar-l-auto mar-r-20 select-container">
  63. <view class="flex-items">
  64. <uni-data-select v-model="user.departmentId" :localdata="departmentOptions" :clear="false"
  65. class="custom-select"></uni-data-select>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="button-container">
  71. <button @click="handleSave" class="save-button">
  72. 保存
  73. </button>
  74. <button @click="handlerLogout" class="logout-button">
  75. 退出登录
  76. </button>
  77. </view>
  78. </view>
  79. </template>
  80. <script>
  81. // import {
  82. // memberDetail,
  83. // memberUpdate
  84. // } from '@/config/api';
  85. import {
  86. mapMutations,
  87. mapActions,
  88. mapGetters
  89. } from 'vuex';
  90. import {
  91. UPLOAD_URL
  92. } from '@/common/config.js'
  93. export default {
  94. data() {
  95. return {
  96. fileList: [],
  97. user: {},
  98. token: "",
  99. companyOptions: [{
  100. value: 1,
  101. text: '科技有限公司'
  102. },
  103. {
  104. value: 2,
  105. text: '网络科技公司'
  106. },
  107. {
  108. value: 3,
  109. text: '软件开发公司'
  110. }
  111. ],
  112. departmentOptions: [{
  113. value: 1,
  114. text: '技术部'
  115. },
  116. {
  117. value: 2,
  118. text: '产品部'
  119. },
  120. {
  121. value: 3,
  122. text: '运营部'
  123. },
  124. {
  125. value: 4,
  126. text: '市场部'
  127. }
  128. ]
  129. };
  130. },
  131. computed: {
  132. ...mapGetters(['userInfo'])
  133. },
  134. onLoad() {
  135. this.token = uni.getStorageSync('access_token')
  136. },
  137. onShow() {
  138. this.detail()
  139. console.log(this.user)
  140. },
  141. methods: {
  142. ...mapActions(['logout']),
  143. handlerLogout() {
  144. this.logout()
  145. uni.$u.toast("退出登录")
  146. uni.navigateBack({
  147. delta: 1 // delta 表示返回的页面数,1 表示返回上一页
  148. });
  149. },
  150. // 新增图片
  151. async afterRead(event) {
  152. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  153. let lists = [].concat(event.file)
  154. console.log(lists, "list")
  155. let fileListLen = this.fileList.length
  156. for (let i = 0; i < lists.length; i++) {
  157. const result = await this.uploadFilePromise(lists[i].thumb)
  158. this.user.avatar = result.data.link
  159. let item = this.fileList[fileListLen]
  160. }
  161. // memberUpdate(this.user)
  162. },
  163. uploadFilePromise(url) {
  164. return new Promise((resolve, reject) => {
  165. let a = uni.uploadFile({
  166. url: UPLOAD_URL,
  167. filePath: url,
  168. header: {
  169. "Blade-Auth": this.token
  170. },
  171. name: 'file',
  172. formData: {
  173. user: 'test'
  174. },
  175. success: (res) => {
  176. resolve(JSON.parse(res.data))
  177. }
  178. });
  179. })
  180. },
  181. // async detail() {
  182. // const data = await memberDetail()
  183. // if (data.code == 200) {
  184. // this.user = data.data
  185. // uni.setStorageSync('user', this.user)
  186. // }
  187. // },
  188. // async handleSave() {
  189. // try {
  190. // const result = await memberUpdate(this.user)
  191. // console.log(result, "12")
  192. // if (result.code === 200) {
  193. // console.log("12")
  194. //
  195. // // 重新获取最新数据
  196. // await this.detail()
  197. // uni.showToast({
  198. // title: '保存成功',
  199. // icon: 'success',
  200. // duration: 2000
  201. // });
  202. // } else {
  203. // uni.showToast({
  204. // title: '保存失败',
  205. // icon: 'success',
  206. // duration: 2000
  207. // });
  208. // }
  209. // } catch (error) {
  210. // uni.showToast({
  211. // title: '保存失败',
  212. // icon: 'success',
  213. // duration: 2000
  214. // });
  215. // console.error('Save error:', error)
  216. // }
  217. // },
  218. },
  219. };
  220. </script>
  221. <style>
  222. .avatar-region {
  223. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  224. border-radius: 40rpx;
  225. width: 700rpx;
  226. height: auto;
  227. padding-bottom: 30rpx;
  228. padding-top: 30rpx;
  229. background-color: white;
  230. margin-top: 30rpx;
  231. margin-bottom: 30rpx;
  232. margin-left: 25rpx;
  233. }
  234. .info-region {
  235. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  236. border-radius: 40rpx;
  237. width: 700rpx;
  238. height: auto;
  239. padding-bottom: 30rpx;
  240. padding-top: 30rpx;
  241. background-color: white;
  242. margin-top: 30rpx;
  243. margin-bottom: 30rpx;
  244. margin-left: 25rpx;
  245. }
  246. .avatar {
  247. width: 130rpx;
  248. height: 130rpx;
  249. border-radius: 50%;
  250. overflow: hidden;
  251. }
  252. .button-container {
  253. padding: 0 32rpx;
  254. margin-top: 60rpx;
  255. }
  256. .save-button {
  257. width: 100%;
  258. height: 88rpx;
  259. background: #2979ff;
  260. border-radius: 44rpx;
  261. font-size: 32rpx;
  262. color: #FFFFFF;
  263. margin-bottom: 30rpx;
  264. }
  265. .logout-button {
  266. width: 100%;
  267. height: 88rpx;
  268. background: #FF4748;
  269. border-radius: 44rpx;
  270. font-size: 32rpx;
  271. color: #FFFFFF;
  272. }
  273. .select-container {
  274. width: 400rpx;
  275. }
  276. /* 自定义下拉框样式 */
  277. .custom-select {
  278. width: 100% !important;
  279. }
  280. /* 确保下拉框内容可以完整显示 */
  281. :deep(.uni-select) {
  282. width: 100% !important;
  283. }
  284. :deep(.uni-select__input-box) {
  285. width: 100% !important;
  286. padding-right: 30rpx !important;
  287. }
  288. :deep(.uni-select__input-text) {
  289. flex: 1;
  290. }
  291. :deep(.uni-select__selector) {
  292. width: 100% !important;
  293. }
  294. </style>