首次完整推送,
V:1.20240808.006
This commit is contained in:
113
uni_modules/uni-feedback/pages/opendb-feedback/detail.vue
Normal file
113
uni_modules/uni-feedback/pages/opendb-feedback/detail.vue
Normal file
@ -0,0 +1,113 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<unicloud-db ref="udb" v-slot:default="{data, loading, error, options}" :options="options" collection="opendb-feedback" field="content,imgs,contact,mobile" :where="queryWhere" :getone="true" :manual="true">
|
||||
<view v-if="error">{{error.message}}</view>
|
||||
<view v-else-if="loading">
|
||||
<uni-load-more :contentText="loadMore" status="loading"></uni-load-more>
|
||||
</view>
|
||||
<view v-else-if="data">
|
||||
<view>
|
||||
<text>留言内容/回复内容</text>
|
||||
<text>{{data.content}}</text>
|
||||
</view>
|
||||
<view>
|
||||
<text>图片列表</text>
|
||||
<template v-for="(file, j) in data.imgs">
|
||||
<uni-file-picker v-if="file.fileType == 'image'" :value="file" :file-mediatype="file.fileType" return-type="object" readonly></uni-file-picker>
|
||||
<uni-link v-else :href="file.url" :text="file.url"></uni-link>
|
||||
</template>
|
||||
</view>
|
||||
<view>
|
||||
<text>联系人</text>
|
||||
<text>{{data.contact}}</text>
|
||||
</view>
|
||||
<view>
|
||||
<text>联系电话</text>
|
||||
<text>{{data.mobile}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</unicloud-db>
|
||||
<view class="btns">
|
||||
<button type="primary" @click="handleUpdate">修改</button>
|
||||
<button type="warn" class="btn-delete" @click="handleDelete">删除</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// 由schema2code生成,包含校验规则和enum静态数据
|
||||
import { enumConverter } from '../../js_sdk/validator/opendb-feedback.js';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
queryWhere: '',
|
||||
loadMore: {
|
||||
contentdown: '',
|
||||
contentrefresh: '',
|
||||
contentnomore: ''
|
||||
},
|
||||
options: {
|
||||
// 将scheme enum 属性静态数据中的value转成text
|
||||
...enumConverter
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad(e) {
|
||||
this._id = e.id
|
||||
},
|
||||
onReady() {
|
||||
if (this._id) {
|
||||
this.queryWhere = '_id=="' + this._id + '"'
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleUpdate() {
|
||||
// 打开修改页面
|
||||
uni.navigateTo({
|
||||
url: './edit?id=' + this._id,
|
||||
events: {
|
||||
// 监听修改页面成功修改数据后, 刷新当前页面数据
|
||||
refreshData: () => {
|
||||
this.$refs.udb.loadData({
|
||||
clear: true
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
handleDelete() {
|
||||
this.$refs.udb.remove(this._id, {
|
||||
success: (res) => {
|
||||
// 删除数据成功后跳转到list页面
|
||||
uni.navigateTo({
|
||||
url: './list'
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.btns {
|
||||
margin-top: 10px;
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.btns button {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.btn-delete {
|
||||
margin-left: 10px;
|
||||
}
|
||||
</style>
|
167
uni_modules/uni-feedback/pages/opendb-feedback/edit.vue
Normal file
167
uni_modules/uni-feedback/pages/opendb-feedback/edit.vue
Normal file
@ -0,0 +1,167 @@
|
||||
<template>
|
||||
<view class="uni-container">
|
||||
<uni-forms ref="form" :value="formData" validate-trigger="submit" err-show-type="toast">
|
||||
<uni-forms-item name="content" label="留言内容/回复内容" required>
|
||||
<textarea @input="binddata('content', $event.detail.value)" class="uni-textarea-border" v-model="formData.content" trim="right"></textarea>
|
||||
</uni-forms-item>
|
||||
<uni-forms-item name="imgs" label="图片列表">
|
||||
<uni-file-picker file-mediatype="image" :limit="6" return-type="array" v-model="formData.imgs"></uni-file-picker>
|
||||
</uni-forms-item>
|
||||
<uni-forms-item name="contact" label="联系人">
|
||||
<uni-easyinput v-model="formData.contact" trim="both"></uni-easyinput>
|
||||
</uni-forms-item>
|
||||
<uni-forms-item name="mobile" label="联系电话">
|
||||
<uni-easyinput v-model="formData.mobile" trim="both"></uni-easyinput>
|
||||
</uni-forms-item>
|
||||
<view class="uni-button-group">
|
||||
<button type="primary" class="uni-button" @click="submit">提交</button>
|
||||
</view>
|
||||
</uni-forms>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { validator } from '../../js_sdk/validator/opendb-feedback.js';
|
||||
|
||||
const db = uniCloud.database();
|
||||
const dbCollectionName = 'opendb-feedback';
|
||||
|
||||
function getValidator(fields) {
|
||||
let result = {}
|
||||
for (let key in validator) {
|
||||
if (fields.indexOf(key) > -1) {
|
||||
result[key] = validator[key]
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export default {
|
||||
data() {
|
||||
let formData = {
|
||||
"content": "",
|
||||
"imgs": [],
|
||||
"contact": "",
|
||||
"mobile": ""
|
||||
}
|
||||
return {
|
||||
formData,
|
||||
formOptions: {},
|
||||
rules: {
|
||||
...getValidator(Object.keys(formData))
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad(e) {
|
||||
if (e.id) {
|
||||
const id = e.id
|
||||
this.formDataId = id
|
||||
this.getDetail(id)
|
||||
}
|
||||
},
|
||||
onReady() {
|
||||
this.$refs.form.setRules(this.rules)
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 触发表单提交
|
||||
*/
|
||||
submit() {
|
||||
uni.showLoading({
|
||||
mask: true
|
||||
})
|
||||
this.$refs.form.validate().then((res) => {
|
||||
this.submitForm(res)
|
||||
}).catch(() => {
|
||||
uni.hideLoading()
|
||||
})
|
||||
},
|
||||
|
||||
submitForm(value) {
|
||||
// 使用 clientDB 提交数据
|
||||
db.collection(dbCollectionName).doc(this.formDataId).update(value).then((res) => {
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: '修改成功'
|
||||
})
|
||||
this.getOpenerEventChannel().emit('refreshData')
|
||||
setTimeout(() => uni.navigateBack(), 500)
|
||||
}).catch((err) => {
|
||||
uni.showModal({
|
||||
content: err.message || '请求服务失败',
|
||||
showCancel: false
|
||||
})
|
||||
}).finally(() => {
|
||||
uni.hideLoading()
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取表单数据
|
||||
* @param {Object} id
|
||||
*/
|
||||
getDetail(id) {
|
||||
uni.showLoading({
|
||||
mask: true
|
||||
})
|
||||
db.collection(dbCollectionName).doc(id).field("content,imgs,contact,mobile").get().then((res) => {
|
||||
const data = res.result.data[0]
|
||||
if (data) {
|
||||
this.formData = data
|
||||
}
|
||||
}).catch((err) => {
|
||||
uni.showModal({
|
||||
content: err.message || '请求服务失败',
|
||||
showCancel: false
|
||||
})
|
||||
}).finally(() => {
|
||||
uni.hideLoading()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.uni-container {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.uni-input-border,
|
||||
.uni-textarea-border {
|
||||
width: 100%;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
border: 1px #e5e5e5 solid;
|
||||
border-radius: 5px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.uni-input-border {
|
||||
padding: 0 10px;
|
||||
height: 35px;
|
||||
|
||||
}
|
||||
|
||||
.uni-textarea-border {
|
||||
padding: 10px;
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.uni-button-group {
|
||||
margin-top: 50px;
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.uni-button {
|
||||
width: 184px;
|
||||
padding: 12px 20px;
|
||||
font-size: 14px;
|
||||
border-radius: 4px;
|
||||
line-height: 1;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
70
uni_modules/uni-feedback/pages/opendb-feedback/list.vue
Normal file
70
uni_modules/uni-feedback/pages/opendb-feedback/list.vue
Normal file
@ -0,0 +1,70 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}" collection="opendb-feedback" field="content,imgs,contact,mobile">
|
||||
<view v-if="error">{{error.message}}</view>
|
||||
<view v-else-if="data">
|
||||
<uni-list>
|
||||
<uni-list-item v-for="(item, index) in data" :key="index" showArrow :clickable="true" @click="handleItemClick(item._id)">
|
||||
<template v-slot:body>
|
||||
<text>
|
||||
<!-- 此处默认显示为_id,请根据需要自行修改为其他字段 -->
|
||||
<!-- 如果使用了联表查询,请参考生成的 admin 项目中 list.vue 页面的绑定字段的写法 -->
|
||||
{{item._id}}
|
||||
</text>
|
||||
</template>
|
||||
</uni-list-item>
|
||||
</uni-list>
|
||||
</view>
|
||||
<uni-load-more :status="loading?'loading':(hasMore ? 'more' : 'noMore')"></uni-load-more>
|
||||
</unicloud-db>
|
||||
<uni-fab ref="fab" horizontal="right" vertical="bottom" :pop-menu="false" @fabClick="fabClick" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
loadMore: {
|
||||
contentdown: '',
|
||||
contentrefresh: '',
|
||||
contentnomore: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
onPullDownRefresh() {
|
||||
this.$refs.udb.loadData({
|
||||
clear: true
|
||||
}, () => {
|
||||
uni.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
onReachBottom() {
|
||||
this.$refs.udb.loadMore()
|
||||
},
|
||||
methods: {
|
||||
handleItemClick(id) {
|
||||
uni.navigateTo({
|
||||
url: './detail?id=' + id
|
||||
})
|
||||
},
|
||||
fabClick() {
|
||||
// 打开新增页面
|
||||
uni.navigateTo({
|
||||
url: './opendb-feedback',
|
||||
events: {
|
||||
// 监听新增数据成功后, 刷新当前页面数据
|
||||
refreshData: () => {
|
||||
this.$refs.udb.loadData({
|
||||
clear: true
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
@ -0,0 +1,141 @@
|
||||
<template>
|
||||
<view class="uni-container">
|
||||
<uni-forms ref="form" :value="formData" validate-trigger="submit" err-show-type="toast">
|
||||
<uni-forms-item name="content" label="留言内容/回复内容" required>
|
||||
<textarea @input="binddata('content', $event.detail.value)" class="uni-textarea-border"
|
||||
v-model="formData.content" trim="right"></textarea>
|
||||
</uni-forms-item>
|
||||
<uni-forms-item name="imgs" label="图片列表">
|
||||
<uni-file-picker file-mediatype="image" :limit="6" return-type="array" v-model="formData.imgs">
|
||||
</uni-file-picker>
|
||||
</uni-forms-item>
|
||||
<uni-forms-item name="contact" label="联系人">
|
||||
<uni-easyinput v-model="formData.contact" trim="both"></uni-easyinput>
|
||||
</uni-forms-item>
|
||||
<uni-forms-item name="mobile" label="联系电话">
|
||||
<uni-easyinput v-model="formData.mobile" trim="both"></uni-easyinput>
|
||||
</uni-forms-item>
|
||||
<view class="uni-button-group">
|
||||
<button type="primary" class="uni-button" @click="submit">提交</button>
|
||||
</view>
|
||||
</uni-forms>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
validator
|
||||
} from '../../js_sdk/validator/opendb-feedback.js';
|
||||
console.log(validator);
|
||||
const db = uniCloud.database();
|
||||
const dbCollectionName = 'opendb-feedback';
|
||||
|
||||
function getValidator(fields) {
|
||||
let result = {}
|
||||
for (let key in validator) {
|
||||
if (fields.indexOf(key) > -1) {
|
||||
result[key] = validator[key]
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export default {
|
||||
data() {
|
||||
let formData = {
|
||||
"content": "",
|
||||
"imgs": [],
|
||||
"contact": "",
|
||||
"mobile": ""
|
||||
}
|
||||
return {
|
||||
formData,
|
||||
formOptions: {},
|
||||
rules: {
|
||||
...getValidator(Object.keys(formData))
|
||||
}
|
||||
}
|
||||
},
|
||||
onReady() {
|
||||
this.$refs.form.setRules(this.rules)
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 触发表单提交
|
||||
*/
|
||||
submit() {
|
||||
uni.showLoading({
|
||||
mask: true
|
||||
})
|
||||
this.$refs.form.validate().then((res) => {
|
||||
this.submitForm(res)
|
||||
}).catch(() => {
|
||||
uni.hideLoading()
|
||||
})
|
||||
},
|
||||
|
||||
submitForm(value) {
|
||||
// 使用 clientDB 提交数据
|
||||
db.collection(dbCollectionName).add(value).then((res) => {
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: '提交成功'
|
||||
})
|
||||
this.getOpenerEventChannel().emit('refreshData')
|
||||
setTimeout(() => uni.navigateBack(), 500)
|
||||
}).catch((err) => {
|
||||
uni.showModal({
|
||||
content: err.message || '请求服务失败',
|
||||
showCancel: false
|
||||
})
|
||||
}).finally(() => {
|
||||
uni.hideLoading()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.uni-container {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.uni-input-border,
|
||||
.uni-textarea-border {
|
||||
width: 100%;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
border: 1px #e5e5e5 solid;
|
||||
border-radius: 5px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.uni-input-border {
|
||||
padding: 0 10px;
|
||||
height: 35px;
|
||||
|
||||
}
|
||||
|
||||
.uni-textarea-border {
|
||||
padding: 10px;
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.uni-button-group {
|
||||
margin-top: 50px;
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.uni-button {
|
||||
width: 184px;
|
||||
padding: 12px 20px;
|
||||
font-size: 14px;
|
||||
border-radius: 4px;
|
||||
line-height: 1;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
Reference in New Issue
Block a user