index.vue 4.6 KB

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