info.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. {extend name="public/base"/}
  2. {block name="css"}
  3. <style>
  4. .avatar {width:100px;height:100px;margin:0 auto;}
  5. </style>
  6. {/block}
  7. {block name="body"}
  8. <van-nav-bar
  9. class="nav-theme"
  10. :fixed="true"
  11. :placeholder="true"
  12. left-text="返回"
  13. left-arrow
  14. @click-left="onBack"
  15. >
  16. <template #title>
  17. <span class="text-white">个人信息</span>
  18. </template>
  19. </van-nav-bar>
  20. <van-form @submit="onSubmit">
  21. <van-cell-group>
  22. <div style="width:100%;height:10px;"></div>
  23. <div class="avatar">
  24. <van-uploader :after-read="afterRead" :before-read="beforeRead" :max-size="1024 * 1024" @oversize="onOversize">
  25. <van-image
  26. width="100"
  27. height="100"
  28. fit="cover"
  29. round
  30. :src="avatar"
  31. ></van-image>
  32. </van-uploader>
  33. </div>
  34. <div style="width:100%;height:10px;"></div>
  35. <van-field
  36. v-if="!user.has_account"
  37. v-model="user.account"
  38. required
  39. label="账号"
  40. placeholder="请输入账号"
  41. :rules="[{ required: true, message: '请输入账号' }]"
  42. ></van-field>
  43. <van-field
  44. v-if="user.has_account"
  45. v-model="user.account"
  46. disabled
  47. label="账号"
  48. ></van-field>
  49. <van-field
  50. v-model="user.nickname"
  51. label="昵称"
  52. required
  53. placeholder="请输入昵称"
  54. :rules="[{ required: true, message: '请输入昵称' }]"
  55. ></van-field>
  56. <van-field
  57. required
  58. label="性别"
  59. :rules="[{ required: true, message: '请选择性别' }]"
  60. >
  61. <template #input>
  62. <van-radio-group v-model="user.gender" direction="horizontal">
  63. <van-radio :name="1">男</van-radio>
  64. <van-radio :name="2">女</van-radio>
  65. </van-radio-group>
  66. </template>
  67. </van-field>
  68. <van-field
  69. v-model="user.birthday"
  70. required
  71. readonly
  72. label="出生日期"
  73. placeholder="请选择出生日期"
  74. @click="toggleBirthday(true)"
  75. :rules="[{ required: true, message: '请选择出生日期' }]"
  76. ></van-field>
  77. <van-popup v-model:show="birthday_show" position="bottom">
  78. <van-date-picker
  79. v-model="birthday"
  80. title="出生日期"
  81. :min-date="minDate"
  82. @confirm="onBirthday"
  83. @cancel="toggleBirthday(false)"
  84. ></van-date-picker>
  85. </van-popup>
  86. </van-cell-group>
  87. <div style="margin: 16px;">
  88. <van-button round block type="primary" native-type="submit">
  89. 提交
  90. </van-button>
  91. </div>
  92. </van-form>
  93. {/block}
  94. {block name="script"}
  95. <script>
  96. function v_setup() {
  97. let base = {};
  98. //基础
  99. let user = {$user};
  100. base.birthday = Vue.ref(user.birthday ? user.birthday.split('-') : []);
  101. base.has_account = (user.account !== '');
  102. base.user = Vue.reactive(user);
  103. base.onBack = () => {
  104. location.href = "{:url('my/index')}";
  105. };
  106. //头像
  107. base.avatar = Vue.computed(()=>{
  108. return base.user.avatar ? base.user.avatar : "__COMMON_IMAGES__/default_avatar.png";
  109. });
  110. base.beforeRead = (file) => {
  111. if (file.type.indexOf('image/') === -1) {
  112. vant.showToast('请上传图片');
  113. return false;
  114. }
  115. return true;
  116. };
  117. base.afterRead = (file) => {
  118. const formData = new FormData();
  119. formData.append("file", file.file);
  120. postFile("upload/image",formData).then(({data})=>{
  121. base.user.avatar = data.src;
  122. });
  123. return true;
  124. };
  125. base.onOversize = () => {
  126. vant.showToast('文件大小不能超过1MB');
  127. return false;
  128. };
  129. //日期
  130. base.birthday_show = Vue.ref(false);
  131. base.minDate = new Date(1900, 0, 1);
  132. base.toggleBirthday = (value) => {
  133. base.birthday_show.value = value;
  134. };
  135. base.onBirthday = (value) => {
  136. base.user.birthday = value.selectedValues.join('-');
  137. base.birthday_show.value = false;
  138. };
  139. //表单提交
  140. base.onSubmit = () => {
  141. if (base.user.avatar === '') {
  142. vant.showToast('请上传头像');
  143. }
  144. if (base.user.gender === 0) {
  145. vant.showToast('请选择性别');
  146. }
  147. postJson('/my/infoPost',base.user).then(() => {
  148. location.href = "{:url('my/index')}";
  149. });
  150. };
  151. return base;
  152. }
  153. </script>
  154. {/block}