persion.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <script setup>
  2. import { ref, onMounted } from 'vue'
  3. import serverConfig from "../serverConfig"
  4. const router = useRouter()
  5. const userInfo = useUserInfoStore()
  6. const alias = ref("")
  7. const gender = ref("")
  8. const defaultSchool = ref("")
  9. const defaultSchoolAddress = ref("")
  10. const username = ref("")
  11. const reset = ref(true)
  12. const newPasswordStr = ref("")
  13. onMounted(() => {
  14. setTimeout(() => {
  15. // console.log(userInfo)
  16. alias.value = userInfo.value.alias
  17. gender.value = userInfo.value.gender
  18. defaultSchool.value = userInfo.value.defaultSchool
  19. defaultSchoolAddress.value = userInfo.value.defaultSchoolAddress
  20. username.value = userInfo.value.username
  21. }, 100);
  22. let url = new URL(location.href)
  23. if (url.searchParams.get("name") && url.searchParams.get("resetKey")) {
  24. reset.value = false
  25. }
  26. })
  27. const updateProfile = () => {
  28. let obj = {
  29. alias: alias.value,
  30. gender: gender.value,
  31. defaultSchool: defaultSchool.value,
  32. defaultSchoolAddress: defaultSchoolAddress.value
  33. }
  34. // const cache = { obj }
  35. const cache = JSON.parse(JSON.stringify(obj))
  36. // str = null;
  37. useFetch('https://api.cocorobo.cn/api/user', {
  38. method: 'PUT',
  39. credentials: 'include',
  40. mode: 'cors',
  41. body: JSON.stringify(cache),
  42. headers: {
  43. 'Content-Type': 'application/json'
  44. }
  45. }).then(res => {
  46. // console.log(res)
  47. if (res.data.value == "") {
  48. alert('变更完成');
  49. userInfo.value.alias = alias.value
  50. userInfo.value.gender = gender.value
  51. userInfo.value.defaultSchool = defaultSchool.value
  52. userInfo.value.defaultSchoolAddress = defaultSchoolAddress.value
  53. }
  54. })
  55. }
  56. const newPassword = async () => {
  57. let url = new URL(location.href)
  58. let obj = {
  59. name: url.searchParams.get("name"),
  60. resetKey: url.searchParams.get("resetKey"),
  61. newPassword: newPasswordStr.value.trim()
  62. }
  63. obj = JSON.parse(JSON.stringify(obj))
  64. // serverConfig.server +
  65. const { data } = await useFetch(serverConfig.server + "/reset/pwd", {
  66. method: 'POST',
  67. body: JSON.stringify(obj)
  68. })
  69. if (data.value == "OK") {
  70. alert('密码重置成功')
  71. router.push("/")
  72. }
  73. }
  74. </script>
  75. <template>
  76. <div class="persion">
  77. <div v-if="reset" class="persion-info content">
  78. <div class="persion-info-img">
  79. <img src="@/assets/img/avatar.svg" alt="">
  80. </div>
  81. <div class="persion-info-content">
  82. <div>
  83. <span>昵称</span>
  84. <input type="text" placeholder="昵称" v-model="alias">
  85. </div>
  86. <div>
  87. <span>性别</span>
  88. <select name="gender" id="Profile__gender" v-model="gender">
  89. <option value="male">男</option>
  90. <option value="female">女</option>
  91. <option value="unknown">保密</option>
  92. </select>
  93. </div>
  94. </div>
  95. <div class="persion-info-content">
  96. <div>
  97. <span>邮箱</span>
  98. <input disabled type="text" placeholder="邮箱" v-model="username">
  99. </div>
  100. <div>
  101. <span>默认学校名称</span>
  102. <input type="text" placeholder="默认学校名称" v-model="defaultSchool">
  103. </div>
  104. </div>
  105. <div class="persion-info-content">
  106. <div>
  107. <span>默认学校地址</span>
  108. <input type="text" placeholder="默认学校地址" v-model="defaultSchoolAddress">
  109. </div>
  110. </div>
  111. <div style="margin-top: 80px;">
  112. <button @click="updateProfile()">提交修改</button>
  113. </div>
  114. </div>
  115. <div v-else class="persion-reset content">
  116. <h2>重置密码</h2>
  117. <div>
  118. <p>新密码</p>
  119. <input type="password" placeholder="请输入新密码" v-model="newPasswordStr">
  120. <button @click="newPassword()">提交</button>
  121. </div>
  122. </div>
  123. </div>
  124. </template>
  125. <style scoped>
  126. .persion {
  127. padding-bottom: 80px;
  128. .persion-info {
  129. margin-top: 80px;
  130. .persion-info-img {
  131. width: 200px;
  132. padding: 25px;
  133. border-radius: 200px;
  134. background-color: #d6e4ea;
  135. overflow: hidden;
  136. margin: 0 auto;
  137. border: 10px solid #b8bfc1;
  138. }
  139. .persion-info-content {
  140. display: flex;
  141. justify-content: space-between;
  142. margin-top: 80px;
  143. text-align: left;
  144. div {
  145. width: 25%;
  146. min-width: 200px;
  147. input {
  148. width: 100%;
  149. outline: none;
  150. padding: 10px 5px;
  151. font-size: 16px;
  152. }
  153. select {
  154. width: 100%;
  155. }
  156. }
  157. }
  158. }
  159. .persion-reset {
  160. padding: 50px 10px;
  161. text-align: left;
  162. h2 {
  163. display: inline-block;
  164. text-align: left;
  165. padding: 20px 60px;
  166. background-color: #1eaaff;
  167. color: #fff;
  168. font-size: 24px;
  169. }
  170. div{
  171. width: 350px;
  172. margin: 80px auto;
  173. text-align: center;
  174. p{
  175. text-align: left;
  176. font-size: 16px;
  177. color: #555;
  178. }
  179. input{
  180. margin: 30px 0;
  181. width: 100%;
  182. border: none;
  183. outline: none;
  184. border-bottom: 3px solid #000;
  185. padding: 5px 0;
  186. }
  187. }
  188. }
  189. }
  190. </style>