index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <form @submit="formSubmit">
  5. <view class="value other" style="display: none;">
  6. <view class="title">id</view>
  7. <view class="label">
  8. <input name="id" class="input" :value="form.id" placeholder="请输入id" />
  9. </view>
  10. </view>
  11. <view class="value icon">
  12. <view class="title">头像</view>
  13. <view class="label">
  14. <u-avatar :text="formatName(form.nickname||'证')" shape="square" fontSize="20"
  15. randomBgColor></u-avatar>
  16. </view>
  17. </view>
  18. <view class="remark">
  19. 实名信息(仅用于咨询、免费估值功能)
  20. </view>
  21. <view class="value other">
  22. <view class="title">姓名</view>
  23. <view class="label">
  24. <input name="name" class="input" :value="form.name" placeholder="请输入真实姓名" />
  25. </view>
  26. </view>
  27. <view class="value other margin">
  28. <view class="title">昵称</view>
  29. <view class="label">
  30. <input name="nickname" class="input" :value="form.nickname" placeholder="请输入昵称" />
  31. </view>
  32. </view>
  33. <view class="value other">
  34. <view class="title">身份证号码</view>
  35. <view class="label">
  36. <input name="card" class="input" :value="form.card" placeholder="请输入身份证号码" />
  37. </view>
  38. </view>
  39. <view class="value other">
  40. <view class="title">手机号</view>
  41. <view class="label">
  42. <input name="phone" class="input" :value="form.phone" placeholder="请输入手机号" />
  43. </view>
  44. </view>
  45. <view class="button">
  46. <button type="warn" size="mini" form-type="submit">保存</button>
  47. </view>
  48. </form>
  49. </view>
  50. </view>
  51. </template>
  52. <script setup lang="ts">
  53. import { getCurrentInstance, computed, ref } from 'vue';
  54. //该依赖已内置不需要单独安装
  55. import { onLoad } from "@dcloudio/uni-app";
  56. // 请求接口
  57. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  58. // openid
  59. const openid = computed(() => {
  60. return uni.getStorageSync('openid');
  61. })
  62. // 基本信息
  63. const config = ref({ logo: '' });
  64. // 用户信息
  65. const form = ref({});
  66. // 字典表
  67. const sexList = ref([]);
  68. onLoad(async () => {
  69. await searchConfig();
  70. await search();
  71. })
  72. // config信息
  73. const searchConfig = async () => {
  74. config.value = uni.getStorageSync('config');
  75. };
  76. // 查询
  77. const search = async () => {
  78. const res = await $api(`login/wxapp/${openid.value}`, 'POST', {});
  79. if (res.errcode == '0') form.value = res.data
  80. };
  81. // 保存
  82. const formSubmit = async (e) => {
  83. let data = e.detail.value;
  84. data = delEmptyQueryNodes(data);
  85. console.log(data);
  86. };
  87. // 去除obj里为null的数据
  88. const delEmptyQueryNodes = (obj = {}) => {
  89. Object.keys(obj).forEach((key) => {
  90. let value = obj[key];
  91. value && typeof value === 'object' && delEmptyQueryNodes(value);
  92. (value === '' || value === null || value === undefined || value.length === 0 || Object.keys(value).length === 0) && delete obj[key];
  93. });
  94. return obj;
  95. };
  96. const formatName = (str) => {
  97. if (str) return str.substr(0, 1) + new Array(str.length).join('');
  98. };
  99. </script>
  100. <style lang="scss" scoped>
  101. .content {
  102. display: flex;
  103. flex-direction: column;
  104. width: 100vw;
  105. height: 100vh;
  106. background-color: var(--footColor);
  107. .one {
  108. .icon {
  109. padding: 2vw;
  110. }
  111. .margin {
  112. margin: 3vw 0 0 0;
  113. }
  114. .other {
  115. padding: 3vw 2vw;
  116. border-bottom: 1px solid var(--footColor);
  117. }
  118. .value {
  119. display: flex;
  120. justify-content: space-between;
  121. align-items: center;
  122. background-color: var(--mainColor);
  123. .label {
  124. .input {
  125. text-align: right;
  126. }
  127. .image {
  128. width: 15vw;
  129. height: 15vw;
  130. border-radius: 20vw;
  131. }
  132. }
  133. }
  134. .remark {
  135. padding: 4vw 2vw;
  136. text-align: center;
  137. color: var(--f99Color);
  138. font-size: var(--font18Size);
  139. }
  140. .button {
  141. margin: 2vw 0 0 0;
  142. text-align: center;
  143. button {
  144. background-color: var(--fFFColor);
  145. font-size: var(--font14Size);
  146. border-radius: 2vw;
  147. }
  148. }
  149. }
  150. }
  151. </style>