deleteAccount.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <view>
  3. <view class="logout__btn" @click="handleOpenModal">
  4. <view>
  5. <trans _t="删除账户" style="letter-spacing: 2px" />
  6. </view>
  7. </view>
  8. <Popup
  9. ref="tipPopupRef"
  10. mode="center"
  11. class="cancel_registration_tip_popup"
  12. title="删除账户"
  13. >
  14. <template #content>
  15. <view class="popup_content">
  16. <view class="warning-text">
  17. <text>{{ $t("cancelRegistrationTips") }}</text>
  18. </view>
  19. <view class="form-group">
  20. <text class="form-label">
  21. <trans _t="请输入密码验证身份" />
  22. </text>
  23. <up-input
  24. type="password"
  25. border="bottom"
  26. :placeholder="t(`请输入密码`)"
  27. v-model="formData.userpass"
  28. >
  29. <template #prefix>
  30. <view class="prefix">
  31. <image
  32. src="@/static/login/password.png"
  33. class="img"
  34. mode="widthFix"
  35. ></image>
  36. </view>
  37. </template>
  38. </up-input>
  39. <p class="info-text">
  40. <trans _t="验证通过后将执行账户删除操作"></trans>
  41. </p>
  42. </view>
  43. </view>
  44. </template>
  45. <template #footer>
  46. <view class="popup__footer">
  47. <view class="popup__footer-btn" @click="onClose">{{
  48. $t("取消")
  49. }}</view>
  50. <view
  51. class="popup__footer-btn popup__footer-btn__confirm"
  52. @click="onConfirm"
  53. >
  54. <up-loading-icon
  55. size="30rpx"
  56. style="margin-right: 12rpx"
  57. v-if="isSubmitting"
  58. ></up-loading-icon>
  59. <text>{{ $t("确认") }}</text>
  60. </view>
  61. </view>
  62. </template>
  63. </Popup>
  64. </view>
  65. </template>
  66. <script setup>
  67. import Popup from "@/components/popup";
  68. import { ref, reactive } from "vue";
  69. import { t } from "@/locale";
  70. import { Toast } from "@/utils";
  71. import { DEL_ACCOUNT } from "@/api";
  72. import { useUserStore, useTabbarStore } from "@/store";
  73. const useUser = useUserStore();
  74. const useTabbar = useTabbarStore();
  75. const tipPopupRef = ref(null);
  76. const isSubmitting = ref(false);
  77. const formData = reactive({
  78. userpass: "",
  79. });
  80. function handleOpenModal() {
  81. tipPopupRef.value && tipPopupRef.value.open();
  82. }
  83. function onClose() {
  84. tipPopupRef.value && tipPopupRef.value.close();
  85. }
  86. function onConfirm() {
  87. if (!formData.userpass.trim()) {
  88. return Toast(t("密码不能为空"));
  89. }
  90. if (isSubmitting.value) return;
  91. isSubmitting.value = true;
  92. DEL_ACCOUNT(formData)
  93. .then((result) => {
  94. Toast(result.msg ? result.msg : t("账户删除成功"));
  95. useUser.loginOut(true);
  96. setTimeout(() => {
  97. uni.switchTab({
  98. url: "/pages/index/index",
  99. success: () => {
  100. useTabbar.getPageCur("index");
  101. useTabbar.getPageIndex(0);
  102. },
  103. });
  104. }, 600);
  105. })
  106. .catch((err) => {
  107. Toast(err.msg);
  108. })
  109. .finally(() => {
  110. isSubmitting.value = false;
  111. });
  112. }
  113. </script>
  114. <style scoped lang="less">
  115. @import url("@/style.less");
  116. .logout__btn {
  117. display: flex;
  118. align-items: cneter;
  119. justify-content: center;
  120. width: 100%;
  121. background-color: var(--black);
  122. color: var(--light);
  123. .size(28rpx);
  124. height: 84rpx;
  125. line-height: 84rpx;
  126. border-radius: 16rpx;
  127. box-sizing: border-box;
  128. }
  129. .cancel_registration_tip_popup :deep(.u-popup__content) {
  130. width: 90%;
  131. }
  132. .cancel_registration_tip_popup :deep(.pop .conts),
  133. .cancel_registration_tip_popup :deep(.pop .top) {
  134. justify-content: center;
  135. }
  136. .footer_btn {
  137. .btn {
  138. background-color: var(--black);
  139. padding: 16rpx 30rpx;
  140. border-radius: 16rpx;
  141. height: 76rpx;
  142. .flex_center();
  143. .size(24rpx);
  144. color: var(--light);
  145. }
  146. }
  147. .popup_content {
  148. line-height: 1.5;
  149. font-size: 30rpx;
  150. .warning-text {
  151. margin-bottom: 14px;
  152. color: #ff4d4f;
  153. text-align: left;
  154. font-size: 28rpx;
  155. }
  156. .form-group {
  157. }
  158. .form-label {
  159. display: block;
  160. margin-bottom: 8px;
  161. font-size: 28rpx;
  162. color: #666;
  163. }
  164. .prefix {
  165. width: 40rpx;
  166. margin-right: 18rpx;
  167. .img {
  168. width: inherit;
  169. display: block;
  170. }
  171. }
  172. .info-text {
  173. font-size: 24rpx;
  174. color: #999;
  175. margin-top: 6px;
  176. line-height: 1.4;
  177. }
  178. }
  179. .popup__footer {
  180. display: flex;
  181. justify-content: space-around;
  182. margin-top: 10px;
  183. .popup__footer-btn {
  184. padding: 8rpx 36rpx;
  185. border: 1rpx solid #333;
  186. border-radius: 12rpx;
  187. font-size: 28rpx;
  188. }
  189. .popup__footer-btn__confirm {
  190. display: flex;
  191. align-items: center;
  192. background-color: var(--black);
  193. color: var(--light);
  194. }
  195. }
  196. </style>