swiper-page.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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="this.$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. newPassword1: '',
  57. defaultAvatarSrc: ''
  58. }
  59. },
  60. created() {
  61. //console.log("create")
  62. this.defaultAvatarSrc = uni.getStorageSync('userInfo').avatar
  63. },
  64. methods: {
  65. // 删除图片
  66. deletePic(event) {
  67. this.fileList.splice(event.index, 1)
  68. },
  69. // 新增图片
  70. async afterRead(event) {
  71. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  72. let lists = [].concat(event.file)
  73. lists.map((item) => {
  74. this.fileList.push({
  75. ...item,
  76. status: 'uploading',
  77. message: '上传中'
  78. })
  79. })
  80. for (let i = 0; i < lists.length; i++) {
  81. const result = await this.uploadFilePromise(lists[i].thumb)
  82. let item = this.fileList[0]
  83. this.fileList.splice(0, 1, Object.assign(item, {
  84. status: 'success',
  85. message: '',
  86. url: result
  87. }))
  88. }
  89. //console.log(this.fileList)
  90. uni.getImageInfo({
  91. src: lists[0].url,
  92. success: (res) => {
  93. //console.log(res, "获取图片信息")
  94. uni.showToast({
  95. duration: 1500,
  96. icon: 'checkmark',
  97. title: '头像已更新'
  98. });
  99. },
  100. fail: (err) => {
  101. console.log(err)
  102. }
  103. });
  104. },
  105. uploadFilePromise(url) {
  106. return new Promise((resolve, reject) => {
  107. uni.showToast({
  108. duration: 1500,
  109. icon: 'none',
  110. title: this.$BASE_URL
  111. });
  112. let a = uni.uploadFile({
  113. url: this.$BASE_URL + '/system/user/profile/avatar',
  114. filePath: url,
  115. name: 'avatarfile',
  116. header: {
  117. Authorization: "Bearer " + uni.getStorageSync('token')
  118. },
  119. success: (res) => {
  120. resolve(res.imgUrl)
  121. }
  122. });
  123. })
  124. },
  125. async doUpdatePwd() {
  126. if (this.from.newPassword.length < 6) {
  127. uni.showToast({
  128. duration: 1500,
  129. icon: 'none',
  130. title: '新密码至少需要 6 位数'
  131. });
  132. return;
  133. }
  134. if (!this.from.newPassword === this.newPassword1) {
  135. uni.showToast({
  136. duration: 1500,
  137. icon: 'none',
  138. title: '2 次新密码不一致'
  139. });
  140. return;
  141. }
  142. // 发送请求
  143. const {
  144. data: res
  145. } = await this.$httpRequest({
  146. url: '/system/user/profile/updatePwd?oldPassword=' + this.from.oldPassword +
  147. "&newPassword=" + this.from.newPassword,
  148. method: 'put'
  149. });
  150. if (res.code === 200) {
  151. uni.showToast({
  152. duration: 1500,
  153. icon: 'checkmark',
  154. title: '密码已更新'
  155. });
  156. this.from = {}
  157. this.newPassword1 = ''
  158. }else{
  159. uni.showToast({
  160. duration: 1500,
  161. icon: 'none',
  162. title: res.msg
  163. });
  164. }
  165. uni.hideLoading()
  166. }
  167. }
  168. }
  169. </script>
  170. <style scoped>
  171. .uploadImgView {
  172. padding-top: 10px;
  173. margin: 0 auto;
  174. background-color: #efefef;
  175. padding: 10px;
  176. border-radius: 10px;
  177. width: 100px;
  178. height: 100px;
  179. }
  180. .updateStyle {
  181. padding: 20px;
  182. }
  183. .xgPwdStyle {
  184. margin-top: 30px;
  185. }
  186. .pwdInput {
  187. margin-bottom: 20px;
  188. width: 100%;
  189. }
  190. .subBotton {
  191. padding-top: 30px;
  192. margin: 0 auto;
  193. width: 150px;
  194. }
  195. </style>