userlogo.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view>
  3. <u-popup :show="userlogo" mode="bottom" round='12' :close-on-click-overlay="false">
  4. <view class="userlogo column">
  5. <view class="mtb30 justify-start align-center ml20">
  6. <u-avatar src="/static/logo.png" size="50"></u-avatar>
  7. <view class="bold mlr20">御君方</view>
  8. <view>申请</view>
  9. </view>
  10. <view class="bold fs36 ml20">授权你的昵称头像信息</view>
  11. <view class="mtb20 justify-between align-center plr20">
  12. <view class="justify-start align-center">
  13. <view class="boxweixin" :class="userinfos.nickname==''?'boxnosel':'boxsel'">
  14. <view v-if="userinfos.nickname">
  15. <u-icon name="checkbox-mark" color="#00aa00" size="22"></u-icon>
  16. </view>
  17. </view>
  18. <view class="ml20">
  19. <view class="base-color-3 bold">第一步</view>
  20. <view class="fs32 base-color-9">请点击授权微信昵称</view>
  21. </view>
  22. </view>
  23. <view class="button-container">
  24. <input
  25. type="nickname"
  26. class="hidden-input"
  27. @blur="onNickNameInput"
  28. @input="onNickNameInput"
  29. />
  30. <button class="custom-button" :class="nameuser==''?'subname':'subavt'">{{nameuser?"已授权":'允许授权'}}</button>
  31. </view>
  32. </view>
  33. <!-- <view class="mtb20 justify-between align-center plr20 mt40">
  34. <view class="justify-start align-center">
  35. <view class="boxweixin" :class="userinfos.nickname==''?'boxnosel':'boxsel'">
  36. <view v-if="userinfos.avatar">√</view>
  37. </view>
  38. <view class="ml20">
  39. <view class="base-color-3 bold">第二步</view>
  40. <view class="fs32 base-color-9">请点击授权微信头像</view>
  41. </view>
  42. </view>
  43. <view class="button-container">
  44. <button open-type="chooseAvatar" @chooseavatar="onChooseAvatar" class="hidden-input"
  45. v-if="nameuser">
  46. 允许授权
  47. </button>
  48. <button class="custom-button sub" @click="shouquan" v-if="nameuser==''">允许授权</button>
  49. <button class="custom-button " :class="avataruser==''?'subname':'subavt'"
  50. v-else>{{avataruser?"已授权":'允许授权'}}</button>
  51. </view>
  52. </view> -->
  53. <view class="submitname" @click="confimrname" :class="nameuser&&avataruser?'subact':'sub'">确定</view>
  54. </view>
  55. </u-popup>
  56. </view>
  57. </template>
  58. <script>
  59. import {editUser}from '@/api/course.js'
  60. export default {
  61. data() {
  62. return {
  63. userlogo:false,
  64. imgname:'',
  65. userinfos:{
  66. nickname:"",
  67. avatar:""
  68. },
  69. }
  70. },
  71. computed: {
  72. nameuser() {
  73. return this.userinfos.nickname
  74. },
  75. avataruser() {
  76. return this.userinfos.avatar
  77. },
  78. },
  79. methods:{
  80. //修改用户昵称以及头像
  81. editUserA(){
  82. this.userinfos=uni.getStorageSync('web_userInfo')?uni.getStorageSync('web_userInfo'):this.userinfos
  83. const data={
  84. nickName:this.userinfos.nickname,
  85. // avatar:this.userinfos.avatar,
  86. }
  87. editUser(data).then(res=>{
  88. if(res.code==200){
  89. setTimeout(()=>{
  90. this.$emit('editUserSuccess')
  91. },100)
  92. }else{
  93. uni.removeStorageSync('web_userInfo')
  94. uni.showToast({
  95. icon:'none',
  96. title:res.msg
  97. });
  98. }
  99. })
  100. },
  101. shouquan(){
  102. if(this.userinfos.nickname==''){
  103. uni.showToast({
  104. icon:'none',
  105. title: "请先授权微信昵称",
  106. });
  107. }
  108. },
  109. confimrname(){
  110. if(this.userinfos.nickname==''){
  111. uni.showToast({
  112. icon:'none',
  113. title: "请授权微信昵称",
  114. });
  115. return
  116. }
  117. // if(this.userinfos.avatar==''){
  118. // uni.showToast({
  119. // icon:'none',
  120. // title: "请授权微信头像",
  121. // });
  122. // return
  123. // }
  124. uni.setStorageSync('web_userInfo',this.userinfos)
  125. this.editUserA()
  126. this.userlogo=false
  127. },
  128. onNickNameInput(e){
  129. console.log(e)
  130. this.userinfos.nickname=e.detail.value
  131. },
  132. onChooseAvatar(e){
  133. this.userinfos.avatar=e.detail.avatarUrl
  134. uni.uploadFile({
  135. url: 'https://h5api.his.cdwjyyh.com'+'/app/common/uploadOSS', //仅为示例,非真实的接口地址
  136. filePath: e.detail.avatarUrl,
  137. name: 'file',
  138. formData: {
  139. 'user': 'test' // 上传附带参数
  140. },
  141. success: (uploadFileRes) => {
  142. console.log(uploadFileRes)
  143. // 根据接口具体返回格式 赋值具体对应url
  144. var data=JSON.parse(uploadFileRes.data)
  145. this.userinfos.avatar=data.url
  146. }
  147. });
  148. },
  149. }
  150. }
  151. </script>
  152. <style scoped lang="scss">
  153. .subname{
  154. background-color: #00aa00;
  155. color: #fff;
  156. }
  157. .subavt{
  158. background-color: #fff;
  159. border: 2rpx #0a0 solid;
  160. color: #00aa00;
  161. }
  162. .boxweixin{
  163. width: 44rpx;
  164. height: 44rpx;
  165. border-radius: 50%;
  166. text-align: center;
  167. line-height: 34rpx;
  168. color: #0a0;
  169. }
  170. .boxnosel{
  171. border: #757575 4rpx solid;
  172. }
  173. .boxsel{
  174. border: #0a0 4rpx solid;
  175. }
  176. .button-container {
  177. position: relative;
  178. width: 240rpx;
  179. }
  180. .hidden-input {
  181. position: absolute;
  182. top: 0;
  183. left: 0;
  184. width: 100%;
  185. height: 100%;
  186. opacity: 0;
  187. z-index: 2;
  188. }
  189. .custom-button {
  190. position: relative;
  191. z-index: 1;
  192. /* 其他样式 */
  193. width:100%;
  194. margin: 0 auto;
  195. height: 80rpx;
  196. line-height: 60rpx;
  197. font-size: 28rpx;
  198. padding: 10rpx 20rpx;
  199. }
  200. .submitname{
  201. width: 90%;
  202. margin: 0 auto;
  203. text-align: center;
  204. padding: 30rpx;
  205. margin-top: 40rpx;
  206. }
  207. .sub{
  208. background-color: #f0f0f0;
  209. color: #0a0;
  210. }
  211. .subact{
  212. background-color: #0a0;
  213. color: #fff;
  214. }
  215. .userlogo{
  216. height: 760rpx;
  217. }
  218. .exsct {
  219. height: 92rpx;
  220. width: 437rpx;
  221. background-color: transparent;
  222. border-radius: 69rpx;
  223. position: absolute;
  224. top: 27rpx;
  225. left: 28rpx;
  226. box-shadow: inset -57rpx 0px 40rpx -26rpx rgba(255, 255, 255, 0.7);
  227. will-change: left, opacity;
  228. animation: leftFade 2s linear infinite;
  229. opacity: 0;
  230. }
  231. </style>