setting.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <view class="wrap">
  3. <navbar :iSimmersive="false" title-color="#ffffff" background="#1b43c4" :placeholder="true" title="会员设置"></navbar>
  4. <view class="avatar" @click="upload">
  5. <view>
  6. <image :src="avatar">
  7. <view class="file">上传</view>
  8. </view>
  9. </view>
  10. <view class="theForm">
  11. <form @submit="formSubmit">
  12. <view class="fields-box">
  13. <view>昵称</view>
  14. <view>
  15. <input type="text" class="uni-input" name="username" :value="username" placeholder="昵称" />
  16. </view>
  17. </view>
  18. <view class="fields-box">
  19. <view>性别</view>
  20. <view>
  21. <picker @change="bindSexPickerChange" :value="sexIndex" :range="sexArray" range-key="name">
  22. <input type="text" class="uni-input" name="sex" disabled="true" :value="sexArray[sexIndex].name" placeholder="性别" />
  23. </picker>
  24. </view>
  25. </view>
  26. <view class="fields-box">
  27. <view>生日</view>
  28. <view>
  29. <picker mode="date" :value="birthday" :start="startDate" :end="endDate" @change="bindDateChange">
  30. <input type="text" class="uni-input" name="birthday" disabled="true" :value="birthday" placeholder="生日" />
  31. </picker>
  32. </view>
  33. </view>
  34. <view class="btn">
  35. <button form-type="submit">提 交</button>
  36. </view>
  37. <view class="logout">
  38. <button @click="logout">退出登录</button>
  39. </view>
  40. </form>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. function getDate(type) {
  46. const date = new Date();
  47. let year = date.getFullYear();
  48. let month = date.getMonth() + 1;
  49. let day = date.getDate();
  50. if (type === 'start') {
  51. year = year - 60;
  52. } else if (type === 'end') {
  53. year = year + 2;
  54. }
  55. month = month > 9 ? month : '0' + month;;
  56. day = day > 9 ? day : '0' + day;
  57. return `${year}-${month}-${day}`;
  58. }
  59. import config from "@/config";
  60. import navbar from "@/components/navbar/navbar";
  61. export default {
  62. components: {
  63. navbar
  64. },
  65. data(){
  66. return {
  67. avatar: "",
  68. username: "",
  69. sex:"男",
  70. birthday:'',
  71. startDate:getDate('start'),
  72. endDate:getDate('end'),
  73. sexIndex: 0,
  74. sexArray: [{name:'男'},{name: '女'}],
  75. };
  76. },
  77. onShow() {
  78. let users = this.$storage.getJson("users");
  79. if(users == null){
  80. this.$utils.navigateTo('public/login');
  81. }else{
  82. this.$http.getUserInfo().then((res)=>{
  83. if(res.status){
  84. this.username = res.data.nickname;
  85. this.sex = res.data.sex;
  86. this.birthday = res.data.birthday;
  87. this.avatar = res.data.avatar;
  88. }
  89. });
  90. }
  91. },
  92. methods:{
  93. bindDateChange: function(e) {
  94. this.birthday = e.detail.value
  95. },
  96. bindSexPickerChange: function(e) {
  97. this.sexIndex = e.detail.value
  98. },
  99. formSubmit(e){
  100. let formdata = e.detail.value;
  101. if(formdata.username.length <= 0){
  102. this.$utils.msg("请填写用户名");
  103. return ;
  104. }
  105. this.$http.editUserInfo(formdata).then((res)=>{
  106. this.$utils.msg(res.info);
  107. });
  108. },
  109. logout(){
  110. this.$store.commit("DELETEUSERS","users");
  111. this.$utils.navigateTo('public/login');
  112. },
  113. upload(){
  114. let users = this.$storage.getJson("users");
  115. let that = this;
  116. uni.chooseImage({
  117. count: 1,
  118. success: (chooseImageRes) => {
  119. const tempFilePaths = chooseImageRes.tempFilePaths;
  120. uni.uploadFile({
  121. url: config.uni_app_web_api_url + '' + '/ucenter/avatar',
  122. filePath: tempFilePaths[0],
  123. name: 'file',
  124. header: { "Auth-Token" : users.token },
  125. success: (uploadFileRes) => {
  126. let res = JSON.parse(uploadFileRes.data);
  127. that.avatar = res.data;
  128. }
  129. });
  130. }
  131. });
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .wrap{
  138. width: 100%;
  139. height: 100vh;
  140. background-color: #fff;
  141. .avatar{
  142. width: 100%;
  143. height: 80px;
  144. text-align: center;
  145. padding: 20px 0;
  146. view {
  147. position: relative;
  148. height: 80px;
  149. width: 80px;
  150. text-align: center;
  151. display: inline-block;
  152. &:before {
  153. width: 80px;
  154. height: 80px;
  155. display: block;
  156. content: " ";
  157. top: 50%;
  158. left: 50%;
  159. transform: translate(-50%,-50%);
  160. position: absolute;
  161. z-index: 99;
  162. background: rgba(0,0,0,0.2);
  163. border-radius: 50%;
  164. }
  165. .file {
  166. top: 50%;
  167. left: 50%;
  168. transform: translate(-50%,-50%);
  169. z-index: 1111;
  170. color: #333;
  171. position: absolute;
  172. display:inline-block; background: #fff;
  173. width: 40px;
  174. height: 20px;
  175. line-height: 20px;
  176. overflow: hidden;
  177. text-decoration: none;
  178. text-indent: 0; cursor: pointer;
  179. border-radius: 5px;
  180. font-size: 13px;
  181. }
  182. image {
  183. width: 80px;
  184. height: 80px;
  185. overflow: hidden;
  186. border-radius: 50%;
  187. position: absolute;
  188. left: 50%;
  189. transform: translateX(-50%);
  190. }
  191. }
  192. }
  193. }
  194. .theForm{
  195. width: 650rpx;
  196. margin: 0 auto;
  197. .fields-box{
  198. width: 100%;
  199. float: left;
  200. font-size: 31rpx;
  201. height: 110rpx;
  202. line-height: 110rpx;
  203. border: 1px solid #e0e0e0;
  204. border-left: 0;
  205. border-right: 0;
  206. &:nth-child(1){
  207. border-bottom: 0;
  208. }
  209. &:nth-child(2){
  210. border-bottom: 0;
  211. }
  212. view:first-child {
  213. float: left;
  214. width: 160rpx;
  215. color: #999;
  216. }
  217. view:last-child {
  218. float: right;
  219. width: 490rpx;
  220. color: #333;
  221. input {
  222. height: 110rpx;
  223. line-height: 110rpx;
  224. }
  225. }
  226. }
  227. .btn{
  228. float: left;
  229. margin: 25rpx 0;
  230. button {
  231. width: 650rpx;
  232. height: 100rpx;
  233. line-height: 100rpx;
  234. text-align: center;
  235. background-color: #1b43c4;
  236. border: 1px solid #1b43c4;
  237. color: #fff;
  238. font-size: 33rpx;
  239. }
  240. }
  241. .logout {
  242. float: left;
  243. button {
  244. width: 650rpx;
  245. height: 100rpx;
  246. line-height: 100rpx;
  247. text-align: center;
  248. background-color: #ffffff;
  249. color: #a1a1a1;
  250. font-size: 33rpx;
  251. border: 0px solid #d6d6d6;
  252. }
  253. }
  254. }
  255. </style>