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

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

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