提交 90d4c398 编写于 作者: H hdx

unicloud-db-contacts: 表单组件 value 已支持 any,将性别类型调整为 number, 和数据库保持一致

上级 86f06b18
<template>
<view class="page">
<unicloud-db ref="udb" v-slot:default="{error}" :collection="collection" loadtime="manual">
<view v-if="error!=null" class="error">{{error.errMsg}}</view>
</unicloud-db>
<unicloud-db ref="udb" :collection="collection" loadtime="manual"></unicloud-db>
<form @submit="onFormSubmit">
<view class="form-item">
<text class="form-item-label">姓名</text>
......@@ -51,7 +49,8 @@
methods: {
onFormSubmit: function (e : FormSubmitEvent) {
const formData = e.detail.value
formData['gender'] = parseInt(formData['gender'] as string)
const genderString = formData['gender'] as string
formData['gender'] = (genderString.length > 0) ? parseInt(genderString) : -1
this.$uniCloudElement!.add(formData, {
showToast: false,
needLoading: true,
......
......@@ -23,7 +23,7 @@
</view>
<view class="form-item">
<text class="form-item-label">性别</text>
<text class="form-item-input">{{displayGender(data[0]['gender'])}}</text>
<text class="form-item-input">{{displayGender(data[0].getNumber('gender'))}}</text>
</view>
<button class="btn-update" type="default" @click="gotoUpdatePage(data[0].getString('_id'))">编辑</button>
</view>
......@@ -60,8 +60,8 @@
this.$uniCloudElement!.loadData()
},
methods: {
displayGender(value : any | null) : string {
const str = (value ?? 0).toString()
displayGender(value : number | null) : string {
const str = value ?? -1
return (GenderList as GenderType[]).find((item : GenderType) : boolean => {
return item.value == str
})!.text;
......
......@@ -62,7 +62,7 @@
where: '',
username: "",
mobile: "",
gender: '',
gender: -1,
comment: "",
email: "",
genderList: GenderList as GenderType[],
......@@ -80,12 +80,12 @@
},
methods: {
radioChange(e : RadioGroupChangeEvent) {
this.gender = e.detail.value
this.gender = parseInt(e.detail.value)
},
update() {
const value = {
username: this.username,
gender: parseInt(this.gender),
gender: this.gender,
mobile: this.mobile,
comment: this.comment,
email: this.email,
......@@ -144,7 +144,7 @@
const data1 = data[0];
this.username = data1.getString('username') ?? "";
this.mobile = data1.getString('mobile') ?? "";
this.gender = data1.getNumber('gender')?.toString() ?? '0';
this.gender = data1.getNumber('gender') ?? -1;
this.comment = data1.getString('comment') ?? "";
this.email = data1.getString('email') ?? "";
}
......
<template>
<view class="page">
<unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}" :collection="collection"
:page-size="10" :getcount="true" loadtime="manual">
<unicloud-db ref="udb" class="udb" v-slot:default="{data, pagination, loading, hasMore, error}"
:collection="collection" :page-size="15" :getcount="true" loadtime="manual">
<view v-if="error!=null" class="error">{{error.errMsg}}</view>
<list-view ref="listView" class="list-view" :scroll-y="true" @scrolltolower="loadMore()">
<list-item class="list-item" v-for="(item, _) in data" @click="gotoDetailPage(item['_id'] as string)">
......@@ -95,6 +95,10 @@
padding: 20px;
}
.udb {
flex: 1;
}
.list-view {
flex: 1;
flex-direction: column;
......
......@@ -2,21 +2,21 @@ export const COLLECTION_NAME = 'opendb-contacts'
export type GenderType = {
text : string,
value : string,
value : number,
}
export const GenderList = [
{
text: "未知",
value: "0"
value: 0
},
{
text: "男",
value: "1"
value: 1
},
{
text: "女",
value: "2"
value: 2
},
] as GenderType[]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册