swiper-page.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="updateStyle">
  3. <view>
  4. <view>
  5. <view>
  6. <u--text text="设置头像" size="20"></u--text>
  7. <u--text style="padding: 10px;" color="#b9b9b9" text="请上传正方形图片" size="12"></u--text>
  8. </view>
  9. <view class="uploadImgView">
  10. <u-upload :fileList="fileList" @afterRead="afterRead" name="1" :maxCount="1" width='100'
  11. height='100' deletable uploadText="请上传正方形图片" :capture="['album']">
  12. <image :src="BASE_URL + defaultAvatarSrc" style="width:100px;height:100px;">
  13. </image>
  14. </u-upload>
  15. </view>
  16. <!-- <view class="subBotton">
  17. <u-button text="保存"></u-button>
  18. </view> -->
  19. </view>
  20. </view>
  21. <view class="xgPwdStyle">
  22. <view>
  23. <view>
  24. <u--text text="修改密码" size="20"></u--text>
  25. </view>
  26. <view style="margin-top: 20px;">
  27. <u--input class="pwdInput" placeholder="旧密码" type="password" v-model="from.oldPassword"
  28. :maxlength="8" border="surround"></u--input>
  29. <u--input class="pwdInput" placeholder="新密码" type="password" v-model="from.newPassword"
  30. :maxlength="8" border="surround"></u--input>
  31. <u--input class="pwdInput" placeholder="确认新密码" type="password" v-model="newPassword1" :maxlength="8"
  32. border="surround">
  33. </u--input>
  34. </view>
  35. <view class="subBotton">
  36. <u-button color="rgb(55,186,189)" text="修改" @click="doUpdatePwd()"></u-button>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import subscription from '../../../pageA/msg/subscription.vue'
  44. export default {
  45. components: {
  46. subscription
  47. },
  48. data() {
  49. return {
  50. scrollable: true,
  51. fileList: [],
  52. from: {
  53. oldPassword: '',
  54. newPassword: ''
  55. },
  56. BASE_URL: this.$BASE_URL,
  57. newPassword1: '',
  58. defaultAvatarSrc: ''
  59. }
  60. },
  61. created() {
  62. this.defaultAvatarSrc = uni.getStorageSync('userInfo').avatar
  63. console.log(this.defaultAvatarSrc)
  64. },
  65. methods: {
  66. // 删除图片
  67. deletePic(event) {
  68. this.fileList.splice(event.index, 1)
  69. },
  70. // 新增图片
  71. async afterRead(event) {
  72. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  73. let lists = [].concat(event.file)
  74. lists.map((item) => {
  75. this.fileList.push({
  76. ...item,
  77. status: 'uploading',
  78. message: '上传中'
  79. })
  80. })
  81. for (let i = 0; i < lists.length; i++) {
  82. const result = await this.uploadFilePromise(lists[i].thumb)
  83. let item = this.fileList[0]
  84. this.fileList.splice(0, 1, Object.assign(item, {
  85. status: 'success',
  86. message: '',
  87. url: result
  88. }))
  89. }
  90. //console.log(this.fileList)
  91. uni.getImageInfo({
  92. src: lists[0].url,
  93. success: (res) => {
  94. //console.log(res, "获取图片信息")
  95. uni.showToast({
  96. duration: 1500,
  97. icon: 'checkmark',
  98. title: '头像已更新'
  99. });
  100. },
  101. fail: (err) => {
  102. console.log(err)
  103. }
  104. });
  105. },
  106. uploadFilePromise(url) {
  107. return new Promise((resolve, reject) => {
  108. uni.showToast({
  109. duration: 1500,
  110. icon: 'none',
  111. title: this.$BASE_URL
  112. });
  113. let a = uni.uploadFile({
  114. url: this.$BASE_URL + '/system/user/profile/avatar',
  115. filePath: url,
  116. name: 'avatarfile',
  117. header: {
  118. Authorization: "Bearer " + uni.getStorageSync('token')
  119. },
  120. success: (res) => {
  121. resolve(res.imgUrl)
  122. }
  123. });
  124. })
  125. },
  126. async doUpdatePwd() {
  127. if (this.from.newPassword.length < 6) {
  128. uni.showToast({
  129. duration: 1500,
  130. icon: 'none',
  131. title: '新密码至少需要 6 位数'
  132. });
  133. return;
  134. }
  135. if (!this.from.newPassword === this.newPassword1) {
  136. uni.showToast({
  137. duration: 1500,
  138. icon: 'none',
  139. title: '2 次新密码不一致'
  140. });
  141. return;
  142. }
  143. // 发送请求
  144. const {
  145. data: res
  146. } = await this.$httpRequest({
  147. url: '/system/user/profile/updatePwd?oldPassword=' + this.from.oldPassword +
  148. "&newPassword=" + this.from.newPassword,
  149. method: 'put'
  150. });
  151. if (res.code === 200) {
  152. uni.showToast({
  153. duration: 1500,
  154. icon: 'checkmark',
  155. title: '密码已更新'
  156. });
  157. this.from = {}
  158. this.newPassword1 = ''
  159. }else{
  160. uni.showToast({
  161. duration: 1500,
  162. icon: 'none',
  163. title: res.msg
  164. });
  165. }
  166. uni.hideLoading()
  167. }
  168. }
  169. }
  170. </script>
  171. <style scoped>
  172. .uploadImgView {
  173. padding-top: 10px;
  174. margin: 0 auto;
  175. background-color: #efefef;
  176. padding: 10px;
  177. border-radius: 10px;
  178. width: 100px;
  179. height: 100px;
  180. }
  181. .updateStyle {
  182. padding: 20px;
  183. }
  184. .xgPwdStyle {
  185. margin-top: 30px;
  186. }
  187. .pwdInput {
  188. margin-bottom: 20px;
  189. width: 100%;
  190. }
  191. .subBotton {
  192. padding-top: 30px;
  193. margin: 0 auto;
  194. width: 150px;
  195. }
  196. </style>