index.vue 6.4 KB

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