set.uvue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <script setup lang='ts'>
  2. import { ref } from 'vue'
  3. import { useUi, type ClFormRule, useForm } from "@/uni_modules/cool-ui";
  4. import { encryptPassword, user, router } from '@/.cool';
  5. import { changeUserPwd, bindWechatOpenId } from "@/services/user";
  6. const ui = useUi();
  7. const formData = ref({
  8. oldPassword: '',
  9. password: ''
  10. })
  11. const { formRef, validate, clearValidate } = useForm();
  12. const rules = new Map<string, ClFormRule[]>([
  13. [
  14. "oldPassword",
  15. [
  16. { required: true, message: '旧密码不能为空' },
  17. ]
  18. ],
  19. [
  20. "password",
  21. [
  22. { required: true, message: '新密码不能为空' },
  23. ]
  24. ]
  25. ])
  26. const handleEdit = () => {
  27. validate((valid, errors) => {
  28. if (valid) {
  29. ui.showConfirm({
  30. title: "修改密码",
  31. message: "确定要修改密码吗?",
  32. async callback(action) {
  33. if (action === "confirm") {
  34. await changeUserPwd({
  35. oldPassword: encryptPassword(formData.value.oldPassword),
  36. password: encryptPassword(formData.value.password)
  37. })
  38. // 执行删除操作
  39. } else {
  40. console.log("用户取消操作");
  41. }
  42. },
  43. });
  44. } else {
  45. ui.showToast({
  46. message: "请填写完整信息",
  47. });
  48. }
  49. });
  50. }
  51. const handleLogout = () => {
  52. ui.showConfirm({
  53. title: "退出登录",
  54. message: "确定要退出登录吗?",
  55. async callback(action) {
  56. if (action === "confirm") {
  57. user.logout()
  58. ui.showToast({
  59. message: "退出登录成功",
  60. });
  61. } else {
  62. console.log("用户取消操作");
  63. }
  64. },
  65. });
  66. }
  67. const loading = ref(false)
  68. const handleBind = () => {
  69. loading.value = true
  70. uni.login({
  71. provider: 'weixin',
  72. success(res) {
  73. bindWechatOpenId({ code: res.code }).then(res => {
  74. uni.showToast({
  75. title: '授权成功,请重新登录'
  76. })
  77. user.logout()
  78. })
  79. }
  80. })
  81. }
  82. </script>
  83. <template>
  84. <view class=" w-full bg-[#fff] shadow rounded-xl mt-[20px] text-[#00A9FF] sidebar flex items-center">
  85. <view class="ww">
  86. <cl-form ref="formRef" :showMessage="false" v-model="formData" labelPosition="left" :rules="rules">
  87. <cl-form-item labelPosition="left" :pt="{ className: '!mb-4' }" label="旧密码" prop="oldPassword">
  88. <cl-input password v-model="formData.oldPassword" placeholder="请输入旧密码"></cl-input>
  89. </cl-form-item>
  90. <cl-form-item labelPosition="left" :pt="{ className: '!mb-4' }" label="新密码" prop="password">
  91. <cl-input password v-model="formData.password" placeholder="请输入新密码"></cl-input>
  92. </cl-form-item>
  93. </cl-form>
  94. </view>
  95. <uni-button
  96. class="h-[30px] rounded-2xl px-[10px] py-[5px] flex flex-row items-center !text-[#fff] justify-center bg-[#007aff] w-[200px] text-[14px] active:bg-[#045bb9]"
  97. type="primary" block @tap="handleEdit">修改密码</uni-button>
  98. <uni-button
  99. class="flex flex-row w-[200px] items-center justify-center gap-2 h-[30px] bg-[#09BA07] rounded-2xl px-[10px] py-[5px] text-[14px] !text-[#fff] active:bg-[#099508] my-[10px]"
  100. @tap="handleBind"><cl-image src="https://oss.xiaoxiongcode.com/static/个人中心/微信.png" mode="heightFix" height="20px"
  101. width="auto"></cl-image>
  102. 绑定微信</uni-button>
  103. <uni-button
  104. class="h-[30px] rounded-2xl px-[10px] py-[5px] flex flex-row items-center !text-[#fff] justify-center text-[14px] bg-[#007aff] w-[200px] active:bg-[#045bb9]"
  105. :loading="loading" type="primary" block @tap="handleLogout">退出登录</uni-button>
  106. </view>
  107. </template>
  108. <style lang="scss" scoped>
  109. .sidebar {
  110. height: calc(80vh - 90px);
  111. max-height: calc(620px - 90px);
  112. padding: 20px;
  113. }
  114. .ww {
  115. width: 70%;
  116. }
  117. </style>