提交 09f56dc1 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

chore: 调整部分示例页面路径

上级 82e9e007
......@@ -277,38 +277,38 @@
}
},
{
"path": "pages/component/web-view-local/web-view-local",
"path": "pages/component/web-view/web-view-local",
"style": {
"navigationBarTitleText": "web-view-local"
}
},
{
"path": "pages/component/unicloud-db-contacts/list",
"path": "pages/component/unicloud-db/unicloud-db",
"style": {
"navigationBarTitleText": "联系人",
"enablePullDownRefresh": true
}
},
{
"path": "pages/component/unicloud-db-contacts/add",
"path": "pages/component/unicloud-db/add",
"style": {
"navigationBarTitleText": "新增联系人"
}
},
{
"path": "pages/component/unicloud-db-contacts/edit",
"path": "pages/component/unicloud-db/edit",
"style": {
"navigationBarTitleText": "编辑联系人"
}
},
{
"path": "pages/component/unicloud-db-contacts/detail",
"path": "pages/component/unicloud-db/detail",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/component/mixin-datacom/mixin-datacom",
"path": "pages/component/datacom/datacom",
"style": {
"navigationBarTitleText": "mixinDatacom"
}
......@@ -581,25 +581,25 @@
},
// #endif
{
"path": "pages/API/action-sheet/action-sheet",
"path": "pages/API/show-action-sheet/show-action-sheet",
"style": {
"navigationBarTitleText": "操作菜单"
}
},
{
"path": "pages/API/modal/modal",
"path": "pages/API/show-modal/show-modal",
"style": {
"navigationBarTitleText": "模态弹窗"
}
},
{
"path": "pages/API/loading/loading",
"path": "pages/API/show-loading/show-loading",
"style": {
"navigationBarTitleText": "加载提示框"
}
},
{
"path": "pages/API/toast/toast",
"path": "pages/API/show-toast/show-toast",
"style": {
"navigationBarTitleText": "消息提示框"
}
......@@ -659,25 +659,25 @@
}
},
{
"path": "pages/API/websocket-socketTask/websocket-socketTask",
"path": "pages/API/websocket/websocket-socketTask",
"style": {
"navigationBarTitleText": "websocket-socketTask"
}
},
{
"path": "pages/API/websocket-global/websocket-global",
"path": "pages/API/websocket/websocket",
"style": {
"navigationBarTitleText": "websocket-global"
}
},
{
"path": "pages/API/unicloud-call-function/unicloud-call-function",
"path": "pages/API/unicloud/call-function",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/API/unicloud-import-object/unicloud-import-object",
"path": "pages/API/unicloud/import-object",
"style": {
"navigationBarTitleText": ""
}
......
......@@ -6,7 +6,7 @@ describe('API-loading', () => {
const isApp = process.env.UNI_OS_NAME === "android" || process.env.UNI_OS_NAME === "ios";
beforeAll(async () => {
page = await program.reLaunch('/pages/API/action-sheet/action-sheet')
page = await program.reLaunch('/pages/API/show-action-sheet/show-action-sheet')
await page.waitFor(500);
});
......
......@@ -12,7 +12,7 @@ describe('API-loading', () => {
}
beforeAll(async () => {
page = await program.reLaunch('/pages/API/modal/modal')
page = await program.reLaunch('/pages/API/show-modal/show-modal')
await page.waitFor('view');
});
......
......@@ -7,7 +7,7 @@ describe('API-toast', () => {
beforeAll(async () => {
page = await program.reLaunch('/pages/API/toast/toast')
page = await program.reLaunch('/pages/API/show-toast/show-toast')
await page.waitFor(600);
});
......
const PAGE_PATH = '/pages/API/call-function/call-function'
describe('unicloud-call-function', () => {
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
await page.setData({
isUniTest: true
})
})
it('callFunction', async () => {
await page.callMethod('callFunction')
const {
callFunctionResult,
callFunctionError,
} = await page.data()
console.error(callFunctionResult)
console.error(callFunctionError)
expect(callFunctionResult['showMessage']).toBe("Hello uniCloud function")
expect(callFunctionResult['event']['num']).toBe(1)
expect(callFunctionResult['event']['str']).toBe('ABC')
})
it('callFunctionWithGeneric', async () => {
await page.callMethod('callFunctionWithGeneric')
const {
genericDemoShowMessage,
} = await page.data()
expect(genericDemoShowMessage).toBe("Hello uniCloud function")
})
})
<template>
<!-- #ifdef APP -->
<scroll-view class="page-scroll-view">
<!-- #endif -->
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-btn-v uni-common-mt">
<button type="primary" @click="callFunction">请求云函数</button>
<button type="primary" @click="callFunctionWithGeneric">请求云函数传入泛型</button>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
title: '请求云函数',
callFunctionResult: {},
callFunctionError: {},
genericDemoShowMessage: '',
isUniTest: false
}
},
onLoad() {
},
onUnload() {
if (this.isUniTest) {
uni.hideToast()
}
},
methods: {
notify(content : string, title : string) {
if (!this.isUniTest) {
uni.showModal({
title,
content,
showCancel: false
})
} else {
console.log(title, content)
}
},
async callFunctionWithGeneric() : Promise<void> {
type EchoCfResult = {
showMessage: string
}
uni.showLoading({
title: '加载中...'
})
await uniCloud.callFunction<EchoCfResult>({
name: 'echo-cf',
data: {
num: 1,
str: 'ABC'
}
}).then(res => {
const result = res.result
uni.hideLoading()
this.genericDemoShowMessage = result.showMessage
this.notify(result.showMessage, '提示')
}).catch((err : any | null) => {
const error = err as UniCloudError
this.callFunctionError = {
errCode: error.errCode,
errMsg: error.errMsg
}
uni.hideLoading()
this.notify(error.errMsg, '错误')
})
},
async callFunction() : Promise<void> {
uni.showLoading({
title: '加载中...'
})
await uniCloud.callFunction({
name: 'echo-cf',
data: {
num: 1,
str: 'ABC'
}
}).then(res => {
const result = res.result
this.callFunctionResult = result
console.log(JSON.stringify(result))
uni.hideLoading()
this.notify(result['showMessage'] as string, '提示')
}).catch((err : any | null) => {
const error = err as UniCloudError
this.callFunctionError = {
errCode: error.errCode,
errMsg: error.errMsg
}
uni.hideLoading()
this.notify(error.errMsg, '错误')
})
}
}
}
</script>
<style>
</style>
<template>
<!-- #ifdef APP -->
<scroll-view class="page-scroll-view">
<!-- #endif -->
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="addTodo">添加Todo</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="addTodoWithGeneric">添加Todo传入泛型</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="randomFail">随机触发失败重试</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="fail">云对象失败调用</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="failWithNumberErrCode">云对象数字错误码</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="success">云对象成功调用</button>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
title: '请求云对象',
todoTitle: '学习编程',
todoContent: '熟悉uts语法',
returnTodoTitle: '',
returnTodoContent: '',
genericDemoReturnTodoTitle: '',
genericDemoReturnTodoContent: '',
failErrCode: '',
failErrDetailTips: '',
failNumberErrCode: 0,
successErrCode: -1,
isUniTest: false
}
},
methods: {
notify(content : string, title : string) {
if (!this.isUniTest) {
uni.showModal({
title,
content,
showCancel: false
})
} else {
console.log(title, content)
}
},
async addTodo() : Promise<void> {
const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
const title = this.todoTitle
const content = this.todoContent
await todo.add<UTSJSONObject>(title, content).then((res : UTSJSONObject) => {
this.returnTodoTitle = res['title'] as string
this.returnTodoContent = res['content'] as string
this.notify(res['showMessage'] as string, '提示')
}).catch((err : any | null) => {
console.log(err)
const error = err as UniCloudError
console.error(error)
})
},
async addTodoWithGeneric() : Promise<void> {
type AddTodoResult = {
title: string,
content: string,
showMessage: string
}
const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
const title = this.todoTitle
const content = this.todoContent
await todo.add<AddTodoResult>(title, content).then((res : AddTodoResult) => {
this.genericDemoReturnTodoTitle = res.title
this.genericDemoReturnTodoContent = res.content
this.notify(res.showMessage, '提示')
}).catch((err : any | null) => {
console.log(err)
const error = err as UniCloudError
console.error(error)
})
},
async randomFail() : Promise<void> {
const todoObj = uniCloud.importObject('todo', {
errorOptions: {
retry: true
}
})
await todoObj.randomFail().then((res : UTSJSONObject) => {
this.notify(res['showMessage'] as string, '提示')
}).catch((err : any | null) => {
const error = err as UniCloudError
console.error(error)
})
},
async fail() : Promise<void> {
const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
await todo.fail().then((res : UTSJSONObject) => {
this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
console.log('todo.fail: ', res);
}).catch((err : any | null) => {
const error = err as UniCloudError
this.failErrCode = error.errCode as string
const detail = error.detail
if (detail != null && detail['tips'] != null) {
this.failErrDetailTips = detail['tips']
}
console.error(error)
})
},
async failWithNumberErrCode() : Promise<void> {
const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
await todo.failWithNumberErrCode().then((res : UTSJSONObject) => {
this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
console.log('todo.fail: ', res);
}).catch((err : any | null) => {
const error = err as UniCloudError
this.failNumberErrCode = error.errCode as number
console.error(error)
})
},
async success() : Promise<void> {
const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
await todo.success().then((res : UTSJSONObject) => {
this.successErrCode = res['errCode'] as number
this.notify(res['showMessage'] as string, '提示')
}).catch((err : any | null) => {
const error = err as UniCloudError
console.error(error)
})
}
}
}
</script>
<style>
</style>
const PAGE_PATH = '/pages/API/websocket-socketTask/websocket-socketTask'
describe('ExtApi-WebSocket', () => {
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
await page.callMethod('jest_connectSocket');
await page.waitFor(1500);
res = await page.data('jest_result');
});
it('Check ', async () => {
expect(res).toBe(2);
});
});
describe('component-native-input', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIos = platformInfo.startsWith('ios')
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/component/input/input')
await page.waitFor('view');
});
// it("beforeAllTestScreenshot", async () => {
// const image = await program.screenshot({
// fullPage: true
// })
// expect(image).toSaveImageSnapshot()
// })
// 测试焦点及键盘弹起
it('focus', async () => {
const input = await page.$('#uni-input-focus');
expect(await input.attribute('focus')).toBe("true")
// expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true)
await page.setData({
focus: false,
})
expect(await input.attribute('focus')).toBe("false")
// await page.waitFor(1000)
// expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false)
// await page.setData({
// focus: true,
// })
// expect(await input.attribute('focus')).toBe(true)
// await page.waitFor(1000)
// expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true)
// await page.setData({
// focus: false,
// })
// expect(await input.attribute('focus')).toBe(false)
// await page.waitFor(1000)
// expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false)
// await page.waitFor(1000)
});
// 测试修改value属性
it("value", async () => {
const input = await page.$('#uni-input-default');
expect(await input.property('value')).toEqual("hello uni-app x")
})
//测试input的类型
it("type", async () => {
const text = await page.$('#uni-input-type-text');
const number = await page.$('#uni-input-type-number');
const digit = await page.$('#uni-input-type-digit');
const tel = await page.$('#uni-input-type-tel');
expect(await text.attribute('type')).toEqual("text")
expect(await number.attribute('type')).toEqual("number")
expect(await digit.attribute('type')).toEqual("digit")
expect(await tel.attribute('type')).toEqual("tel")
})
// 测试密码属性
// it("password", async () => {
// const input = await page.$('.uni-input-password');
// expect(await input.attribute('password')).toBe(true)
// await page.setData({
// inputPassword: false,
// inputPasswordValue: "inputPasswordValue"
// })
// expect(await input.attribute('password')).toBe(false)
// await page.waitFor(500)
// await page.setData({
// inputPassword: true
// })
// })
// 测试placeholder
// it("placeholder", async () => {
// const placeholder1 = await page.$('.uni-input-placeholder1');
// expect(await placeholder1.attribute("placeholder-style")).toMatchObject({
// "color": "red"
// })
// expect(await placeholder1.attribute("placeholder")).toEqual("占位符文字颜色为红色")
// await page.setData({
// inputPlaceHolderStyle: "color:#CC00CC",
// })
// expect(await placeholder1.attribute("placeholder-style")).toMatchObject({
// "color": "#CC00CC"
// })
// await page.setData({
// inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0",
// })
// expect(await placeholder1.attribute("placeholder-style")).toMatchObject({
// "color": "#CC19CC",
// "backgroundColor": "#00b1c0"
// })
// await page.setData({
// inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0;text-align:center;font-size:44px;font-weight:900",
// })
// expect(await placeholder1.attribute("placeholder-style")).toEqual({
// "backgroundColor": "#00b1c0",
// "color": "#CC19CC",
// "fontSize": "44px",
// "fontWeight": "900",
// "textAlign": "center"
// })
// const placeholder2 = await page.$('.uni-input-placeholder2');
// expect(await placeholder2.attribute("placeholder-class")).toMatchObject({
// "backgroundColor": "#008000"
// })
// await page.setData({
// inputPlaceHolderClass: "uni-input-placeholder-class-ts",
// })
// expect(await placeholder2.attribute("placeholder-class")).toMatchObject({
// "backgroundColor": "#FFA500"
// })
// expect(await placeholder2.attribute("placeholder")).toEqual("占位符背景色为绿色")
// })
it("disable", async () => {
const input = await page.$('#uni-input-disable');
expect(await input.attribute("disabled")).toBe("true")
})
it("confirm-type", async () => {
expect(await (await page.$('#uni-input-confirm-send')).attribute("confirmType")).toEqual("send")
expect(await (await page.$('#uni-input-confirm-search')).attribute("confirmType")).toEqual("search")
expect(await (await page.$('#uni-input-confirm-next')).attribute("confirmType")).toEqual("next")
expect(await (await page.$('#uni-input-confirm-go')).attribute("confirmType")).toEqual("go")
expect(await (await page.$('#uni-input-confirm-done')).attribute("confirmType")).toEqual("done")
})
// it("maxlength", async () => {
// const input = await page.$('.uni-input-maxlength');
// await page.setData({
// inputMaxLengthValue: "uni-input-maxlength"
// })
// await page.waitFor(500)
// })
it("cursor-color", async () => {
await page.setData({
cursor_color: "red",
})
await page.waitFor(500)
expect(await (await page.$('#uni-input-cursor-color')).attribute("cursor-color")).toBe("red")
})
it("maxlength", async () => {
const input = await page.$('#uni-input-maxlength');
let str = "";
for (let i = 0; i < 200; i++) {
str += `${i}`
}
await page.setData({
inputMaxLengthValue: str
})
let length = (await input.value()).length
expect(length).toBe(10)
await page.setData({
inputMaxLengthValue: ""
})
})
it("password and value order", async () => {
const input = await page.$('#uni-input-password');
let length = (await input.value()).length
expect(length).toBe(6)
await page.setData({
inputPasswordValue: ""
})
})
it("keyboard height changed after page back", async () => {
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('web')) {
expect(1).toBe(1)
return
}
if (process.env.uniTestPlatformInfo.startsWith('ios')) {
expect(1).toBe(1)
return
}
await program.navigateTo("/pages/API/navigator/new-page/new-page-3")
await page.waitFor(2000);
await program.navigateBack()
await page.waitFor(1000);
await page.setData({
focusedForKeyboardHeightChangeTest: true
})
await page.waitFor(2000);
const keyboardHeight = await page.data('keyboardHeight');
console.log("keyboardHeight :", keyboardHeight);
expect(keyboardHeight).toBeGreaterThan(25)
//reset
await page.setData({
focusedForKeyboardHeightChangeTest: false,
keyboardHeight: 0
})
})
it("afterAllTestScreenshot", async () => {
const image = await program.screenshot({
fullPage: true
})
expect(image).toSaveImageSnapshot()
})
it('both set modelValue and value', async () => {
const input2 = await page.$('#both-model-value');
expect(await input2.value()).toEqual("123")
})
it('digit input .', async () => {
// ios 非 webview 模式规避该测试
// ios input type='digit' 输入 . 实际得到 。,只有系统软键盘才可以输入 .
if(isIos && !process.env.UNI_AUTOMATOR_APP_WEBVIEW){
return
}
await page.setData({
focus: false,
digitValue: '1'
})
await program.pageScrollTo(0)
const digitInput = await page.$('#uni-input-type-digit')
expect(await digitInput.value()).toEqual('1')
if (isAndroid) {
if (platformInfo.indexOf('6') != -1 && platformInfo.indexOf('x86') == -1) {
await program.tap({
x: 200,
y: 850,
})
} else if (platformInfo.indexOf('12') != -1) {
await program.tap({
x: 200,
y: 1500,
})
} else {
await program.tap({
x: 200,
y: 1200,
})
}
} else if (isIos) {
await program.tap({
x: 200,
y: 450,
})
} else {
await program.tap({
x: 200,
y: 400,
})
}
await page.waitFor(1000)
await program.keyboardInput('.2')
await page.waitFor(500)
await program.tap({
x: 0,
y: 0,
})
await page.waitFor(500)
expect(await digitInput.value()).toEqual('1.2');
})
});
<template>
<view class="page">
<unicloud-db ref="udb" :collection="collection" loadtime="manual"></unicloud-db>
<form @submit="onFormSubmit">
<view class="form-item">
<text class="form-item-label">姓名</text>
<input class="form-item-input" placeholder="姓名" name="username" />
</view>
<view class="form-item">
<text class="form-item-label">电话</text>
<input class="form-item-input" placeholder="电话" name="mobile" />
</view>
<view class="form-item">
<text class="form-item-label">邮箱</text>
<input class="form-item-input" placeholder="邮箱地址" name="email" />
</view>
<view class="form-item">
<text class="form-item-label">备注</text>
<textarea class="form-item-input" placeholder="备注" name="comment" maxlength="-1"/>
</view>
<view class="form-item">
<text class="form-item-label">性别</text>
<radio-group class="radio-list" name="gender">
<view class="radio-item" v-for="(item, _) in genderList" :key="item.value">
<radio :value="item.value" />
<text>{{item.text}}</text>
</view>
</radio-group>
</view>
<button class="btn-add" type="primary" form-type="submit">保存</button>
</form>
</view>
</template>
<script>
import { COLLECTION_NAME, GenderType, GenderList, UNICLOUD_DB_CONTACTS_ADD } from './types.uts'
export default {
data() {
return {
collection: COLLECTION_NAME,
genderList: GenderList as GenderType[],
uniCloudElement: null as UniCloudDBElement | null
}
},
onReady() {
this.uniCloudElement = this.$refs['udb'] as UniCloudDBElement
},
methods: {
onFormSubmit: function (e : UniFormSubmitEvent) {
const formData = e.detail.value
const genderString = formData['gender'] as string
formData['gender'] = (genderString.length > 0) ? parseInt(genderString) : -1
console.log('formData', formData)
this.uniCloudElement!.add(formData, {
showToast: false,
needLoading: true,
loadingTitle: "正在保存...",
success: (_ : UniCloudDBAddResult) => {
// TODO 后续通过 EventChannel 实现
uni.$emit(UNICLOUD_DB_CONTACTS_ADD, '')
setTimeout(() => {
uni.navigateBack()
}, 500)
},
fail: (err : any | null) => {
const error = err as UniCloudError
uni.showModal({
content: error.errMsg,
showCancel: false
})
}
})
}
}
}
</script>
<style>
.page {
padding: 15px;
}
.form-item {
flex-direction: row;
margin-bottom: 15px;
align-items: center;
}
.form-item-label {
width: 45px;
margin-right: 10px;
}
.form-item-input {
flex: 1;
font-size: 14px;
color: #666;
border: 1px #e5e5e5 solid;
border-radius: 5px;
padding: 8px;
}
.radio-list {
flex-direction: row;
}
.radio-item {
flex-direction: row;
margin-right: 30px;
align-items: center;
}
.btn-add {
margin-top: 50px;
}
</style>
<template>
<scroll-view class="page">
<unicloud-db ref="udb" v-slot:default="{data, loading, error}" :collection="collection" :where="where"
page-data="replace">
<view v-if="error!=null" class="error">{{error.errMsg}}</view>
<view v-if="loading" class="loading">正在加载...</view>
<view v-if="data.length>0">
<view class="form-item">
<text class="form-item-label">姓名</text>
<text class="form-item-input">{{data[0]['username']}}</text>
</view>
<view class="form-item">
<text class="form-item-label">电话</text>
<text class="form-item-input">{{data[0]['mobile']}}</text>
</view>
<view class="form-item">
<text class="form-item-label">邮箱</text>
<text class="form-item-input">{{data[0]['email']}}</text>
</view>
<view class="form-item">
<text class="form-item-label">备注</text>
<text class="form-item-input">{{data[0]['comment']}}</text>
</view>
<view class="form-item">
<text class="form-item-label">性别</text>
<text class="form-item-input">{{displayGender(data[0].getNumber('gender'))}}</text>
</view>
<button type="default" @click="gotoUpdatePage(data[0].getString('_id'))">编辑</button>
</view>
</unicloud-db>
</scroll-view>
</template>
<script>
import { COLLECTION_NAME, GenderType, GenderList, UNICLOUD_DB_CONTACTS_UPDATE } from './types.uts'
export default {
data() {
return {
collection: '',
where: '',
whereID: '',
uniCloudElement: null as UniCloudDBElement | null
}
},
onLoad(options) {
this.collection = COLLECTION_NAME;
this.whereID = options['id'] as string;
this.where = `_id=='${this.whereID}'`;
},
onShow() {
// TODO 后续通过 EventChannel 实现
uni.$off(UNICLOUD_DB_CONTACTS_UPDATE, this.onDataChange);
},
onUnload() {
// TODO 后续通过 EventChannel 实现
uni.$off(UNICLOUD_DB_CONTACTS_UPDATE, this.onDataChange);
},
onReady() {
this.uniCloudElement = this.$refs['udb'] as UniCloudDBElement
},
methods: {
displayGender(value : number | null) : string {
const str = value ?? -1
return (GenderList as GenderType[]).find((item : GenderType) : boolean => {
return item.value == str
})!.text;
},
gotoUpdatePage(id : string | null) {
// TODO 后续通过 EventChannel 实现
uni.$on(UNICLOUD_DB_CONTACTS_UPDATE, this.onDataChange);
uni.navigateTo({
url: './edit?id=' + id
})
},
onDataChange(_ : string) {
this.uniCloudElement!.loadData()
}
}
}
</script>
<style>
.page {
flex: 1;
padding: 15px;
}
.loading {
align-items: center;
}
.form-item {
flex-direction: row;
margin-bottom: 15px;
align-items: center;
padding: 8px 0;
}
.form-item-label {
width: 45px;
margin-right: 10px;
}
.form-item-input {
flex: 1;
font-size: 14px;
color: #666;
}
</style>
<template>
<scroll-view class="scroll-view">
<unicloud-db ref="udb" v-slot:default="{data, loading, error}" :collection="collection" :where="where"
page-data="replace">
<view v-if="error!=null" class="error">{{error.errMsg}}</view>
<view v-if="loading" class="loading">正在加载...</view>
<form v-if="data.length>0" @submit="onFormSubmit">
<view class="form-item">
<text class="form-item-label">姓名</text>
<input class="form-item-input" placeholder="姓名" name="username" :value="data[0].getString('username')" />
</view>
<view class="form-item">
<text class="form-item-label">电话</text>
<input class="form-item-input" placeholder="电话" name="mobile" :value="data[0].getString('mobile')" />
</view>
<view class="form-item">
<text class="form-item-label">邮箱</text>
<input class="form-item-input" placeholder="邮箱地址" name="email" :value="data[0].getString('email')" />
</view>
<view class="form-item">
<text class="form-item-label">备注</text>
<textarea class="form-item-input" placeholder="备注" name="comment" maxlength="-1" :value="data[0].getString('comment')" />
</view>
<view class="form-item">
<text class="form-item-label">性别</text>
<radio-group class="radio-list" name="gender">
<view class="radio-item" v-for="(item, _) in genderList" :key="item.value">
<radio :value="item.value" :checked="item.value == data[0].getNumber('gender')" />
<text>{{item.text}}</text>
</view>
</radio-group>
</view>
<view class="btn-group">
<button class="btn-submit" type="primary" form-type="submit">保存</button>
<button class="btn-delete" type="warn"
@click="remove(data[0].getString('_id'), data[0].getString('username'))">删除联系人</button>
</view>
</form>
</unicloud-db>
</scroll-view>
</template>
<script>
import { COLLECTION_NAME, GenderType, GenderList, UNICLOUD_DB_CONTACTS_UPDATE, UNICLOUD_DB_CONTACTS_DELETE } from './types.uts'
export default {
data() {
return {
collection: '',
where: '',
genderList: GenderList as GenderType[],
whereID: '',
uniCloudElement: null as UniCloudDBElement | null
}
},
onLoad(options) {
this.collection = COLLECTION_NAME;
this.whereID = options['id'] as string;
this.where = `_id=='${this.whereID}'`;
},
onReady() {
this.uniCloudElement = this.$refs['udb'] as UniCloudDBElement
},
methods: {
onFormSubmit: function (e : UniFormSubmitEvent) {
const formData = e.detail.value
const genderString = formData['gender'] as string
formData['gender'] = (genderString.length > 0) ? parseInt(genderString) : -1
this.uniCloudElement!.update(this.whereID, formData, {
showToast: false,
needLoading: true,
needConfirm: false,
loadingTitle: "正在保存...",
success: (_ : UniCloudDBUpdateResult) => {
// TODO 后续通过 EventChannel 实现
uni.$emit(UNICLOUD_DB_CONTACTS_UPDATE, this.whereID)
setTimeout(() => {
uni.navigateBack()
}, 500)
},
fail: (err : any | null) => {
const error = err as UniCloudError
uni.showModal({
content: error.errMsg,
showCancel: false
})
}
})
},
remove(id : string | null, name : string | null) {
this.uniCloudElement!.remove(id!, {
needConfirm: true,
needLoading: true,
loadingTitle: "正在删除...",
confirmTitle: "确定删除?",
confirmContent: name,
success: (_ : UniCloudDBRemoveResult) => {
// TODO 后续通过 EventChannel 实现
uni.$emit(UNICLOUD_DB_CONTACTS_DELETE, this.whereID)
setTimeout(() => {
uni.navigateBack({
delta: 2
})
}, 500)
},
fail: (err : any | null) => {
const error = err as UniCloudError
uni.showModal({
content: error.errMsg,
showCancel: false
})
}
})
}
}
}
</script>
<style>
.page {
flex: 1;
}
.scroll-view {
padding: 15px;
flex: 1;
}
.loading {
align-items: center;
}
.form-item {
flex-direction: row;
margin-bottom: 15px;
align-items: center;
}
.form-item-label {
width: 45px;
margin-right: 10px;
}
.form-item-input {
flex: 1;
font-size: 14px;
color: #666;
border: 1px #e5e5e5 solid;
border-radius: 5px;
padding: 8px;
}
.radio-list {
flex-direction: row;
}
.radio-item {
flex-direction: row;
margin-right: 30px;
align-items: center;
}
.btn-group {
margin-top: 30px;
}
.btn-delete {
margin-top: 15px;
}
</style>
export const COLLECTION_NAME = 'opendb-contacts'
export type GenderType = {
text : string,
value : number,
}
export const GenderList = [
{
text: "未知",
value: 0
},
{
text: "男",
value: 1
},
{
text: "女",
value: 2
},
] as GenderType[]
export const UNICLOUD_DB_CONTACTS_ADD = 'unicloud-db-contacts-add'
export const UNICLOUD_DB_CONTACTS_UPDATE = 'unicloud-db-contacts-update'
export const UNICLOUD_DB_CONTACTS_DELETE = 'unicloud-db-contacts-delete'
......@@ -73,15 +73,15 @@ const pages = [
// 动态内容
// '/pages/component/web-view/web-view',
// 依赖加载完成回调,单独测试例截图
// '/pages/component/web-view-local/web-view-local',
// '/pages/component/web-view/web-view-local',
// 动态内容
// '/pages/component/unicloud-db-contacts/list',
'/pages/component/unicloud-db-contacts/add',
// '/pages/component/unicloud-db/unicloud-db',
'/pages/component/unicloud-db/add',
// 动态内容
// '/pages/component/unicloud-db-contacts/edit',
// '/pages/component/unicloud-db/edit',
// 动态内容
// '/pages/component/unicloud-db-contacts/detail',
'/pages/component/mixin-datacom/mixin-datacom',
// '/pages/component/unicloud-db/detail',
'/pages/component/datacom/datacom',
// 单独测试例截图
// '/pages/component/general-attribute/general-attribute',
'/pages/component/general-event/general-event',
......@@ -124,12 +124,12 @@ const pages = [
'/pages/API/nodes-info/nodes-info',
'/pages/API/storage/storage',
// 单独测试例截图
// '/pages/API/action-sheet/action-sheet',
// '/pages/API/show-action-sheet/show-action-sheet',
// 单独测试例截图
// '/pages/API/modal/modal',
'/pages/API/loading/loading',
// '/pages/API/show-modal/show-modal',
'/pages/API/show-loading/show-loading',
// 单独测试例截图
// '/pages/API/toast/toast',
// '/pages/API/show-toast/show-toast',
// 单独测试例截图
// '/pages/API/load-font-face/load-font-face',
// 单独测试例截图
......@@ -141,11 +141,11 @@ const pages = [
'/pages/API/request/request',
'/pages/API/upload-file/upload-file',
'/pages/API/download-file/download-file',
'/pages/API/websocket-socketTask/websocket-socketTask',
'/pages/API/websocket/websocket-socketTask',
// 页面销毁时会关闭socket连接,所以规避
// '/pages/API/websocket-global/websocket-global',
'/pages/API/unicloud-call-function/unicloud-call-function',
'/pages/API/unicloud-import-object/unicloud-import-object',
// '/pages/API/websocket/websocket',
'/pages/API/unicloud/call-function',
'/pages/API/unicloud/import-object',
'/pages/API/get-system-info/get-system-info',
'/pages/API/get-device-info/get-device-info',
'/pages/API/get-app-base-info/get-app-base-info',
......
......@@ -21,3 +21,16 @@ uni-app x [开发文档](https://uniapp.dcloud.net.cn/uni-app-x/)
```bash
npx husky@9.0.11
```
#### pages.json
创建 component、API、css 示例页面时,如果该示例页面需要在对应 tabBar 菜单中展示,命名需要遵循以下规则:
- component pages/component/component-name/component-name
- API pages/API/api-name/api-name
- css pages/API/css-name/css-name
增加上述示例页面时,不需要基于平台兼容性补充条件编译,代码提交后,会自动生成对应的条件编译代码,并更新 pages.json。
pages.json 中增加后,需要在 [syntaxdoc](http://git.dcloud.io/uni-app-x/syntaxdoc) 仓库的 modules.json 中维护目录信息。
**注意:** 调整现有页面的路径或平台兼容性,或移除页面时,如果该页面设计截图对比测试,需要同时调整 pages/pages.test.js 中的页面地址。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册