123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <template>
- <view class="content">
- <view class="one">
- <form @submit="formSubmit">
- <view class="value other" style="display: none;">
- <view class="title">id</view>
- <view class="label">
- <input name="id" class="input" :value="form.id" placeholder="请输入id" />
- </view>
- </view>
- <view class="value icon">
- <view class="title">头像</view>
- <view class="label">
- <u-avatar :text="formatName(form.nickname||'证')" shape="square" fontSize="20"
- randomBgColor></u-avatar>
- </view>
- </view>
- <view class="remark">
- 实名信息(仅用于咨询、免费估值功能)
- </view>
- <view class="value other">
- <view class="title">姓名</view>
- <view class="label">
- <input name="name" class="input" :value="form.name" placeholder="请输入真实姓名" />
- </view>
- </view>
- <view class="value other margin">
- <view class="title">昵称</view>
- <view class="label">
- <input name="nickname" class="input" :value="form.nickname" placeholder="请输入昵称" />
- </view>
- </view>
- <view class="value other">
- <view class="title">身份证号码</view>
- <view class="label">
- <input name="card" class="input" :value="form.card" placeholder="请输入身份证号码" />
- </view>
- </view>
- <view class="value other">
- <view class="title">手机号</view>
- <view class="label">
- <input name="phone" class="input" :value="form.phone" placeholder="请输入手机号" />
- </view>
- </view>
- <view class="button">
- <button type="warn" size="mini" form-type="submit">保存</button>
- </view>
- </form>
- </view>
- </view>
- </template>
- <script setup lang="ts">
- import { getCurrentInstance, computed, ref } from 'vue';
- //该依赖已内置不需要单独安装
- import { onLoad } from "@dcloudio/uni-app";
- // 请求接口
- const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
- // openid
- const openid = computed(() => {
- return uni.getStorageSync('openid');
- })
- // 基本信息
- const config = ref({ logo: '' });
- // 用户信息
- const form = ref({});
- // 字典表
- const sexList = ref([]);
- onLoad(async () => {
- await searchConfig();
- await search();
- })
- // config信息
- const searchConfig = async () => {
- config.value = uni.getStorageSync('config');
- };
- // 查询
- const search = async () => {
- const res = await $api(`login/wxapp/${openid.value}`, 'POST', {});
- if (res.errcode == '0') {
- form.value = res.data
- uni.setStorageSync('user', res.data);
- }
- };
- // 保存
- const formSubmit = async (e) => {
- if (form.value._id) {
- let data = e.detail.value;
- data = delEmptyQueryNodes(data);
- const res = await $api(`user/${form.value._id}`, 'POST', data);
- if (res.errcode == '0') search();
- } else {
- uni.navigateTo({
- url: `/pagesHome/login/index`
- })
- }
- };
- // 去除obj里为null的数据
- const delEmptyQueryNodes = (obj = {}) => {
- Object.keys(obj).forEach((key) => {
- let value = obj[key];
- value && typeof value === 'object' && delEmptyQueryNodes(value);
- (value === '' || value === null || value === undefined || value.length === 0 || Object.keys(value).length === 0) && delete obj[key];
- });
- return obj;
- };
- const formatName = (str) => {
- if (str) return str.substr(0, 1) + new Array(str.length).join('');
- };
- </script>
- <style lang="scss" scoped>
- .content {
- display: flex;
- flex-direction: column;
- width: 100vw;
- height: 100vh;
- background-color: var(--footColor);
- .one {
- .icon {
- padding: 2vw;
- }
- .margin {
- margin: 3vw 0 0 0;
- }
- .other {
- padding: 3vw 2vw;
- border-bottom: 1px solid var(--footColor);
- }
- .value {
- display: flex;
- justify-content: space-between;
- align-items: center;
- background-color: var(--mainColor);
- .label {
- .input {
- text-align: right;
- }
- .image {
- width: 15vw;
- height: 15vw;
- border-radius: 20vw;
- }
- }
- }
- .remark {
- padding: 4vw 2vw;
- text-align: center;
- color: var(--f99Color);
- font-size: var(--font18Size);
- }
- .button {
- margin: 2vw 0 0 0;
- text-align: center;
- button {
- background-color: var(--fFFColor);
- font-size: var(--font14Size);
- border-radius: 2vw;
- }
- }
- }
- }
- </style>
|