226 lines
6.9 KiB
JavaScript
226 lines
6.9 KiB
JavaScript
"use strict";
|
||
const common_vendor = require("../../common/vendor.js");
|
||
const js_sdk_validator_comment = require("../../js_sdk/validator/comment.js");
|
||
const db = common_vendor.er.database();
|
||
db.command;
|
||
const dbCollectionName = "comment";
|
||
function getValidator(fields) {
|
||
let result = {};
|
||
for (let key in js_sdk_validator_comment.validator) {
|
||
if (fields.includes(key)) {
|
||
result[key] = js_sdk_validator_comment.validator[key];
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
const _sfc_main = {
|
||
data() {
|
||
let formData = {
|
||
"content": "",
|
||
"root_id": "0",
|
||
"author_id": "",
|
||
"parent_id": "0",
|
||
"article_id": "",
|
||
"like_count": 0,
|
||
"create_time": null,
|
||
"update_time": null,
|
||
"reply_count": 0,
|
||
"ip_location": null
|
||
};
|
||
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() {
|
||
common_vendor.index.showLoading({
|
||
mask: true
|
||
});
|
||
this.$refs.form.validate().then((res) => {
|
||
return this.submitForm(res);
|
||
}).catch(() => {
|
||
}).finally(() => {
|
||
common_vendor.index.hideLoading();
|
||
});
|
||
},
|
||
/**
|
||
* 提交表单
|
||
*/
|
||
submitForm(value) {
|
||
return db.collection(dbCollectionName).doc(this.formDataId).update(value).then((res) => {
|
||
common_vendor.index.showToast({
|
||
title: "修改成功"
|
||
});
|
||
this.getOpenerEventChannel().emit("refreshData");
|
||
setTimeout(() => common_vendor.index.navigateBack(), 500);
|
||
}).catch((err) => {
|
||
common_vendor.index.showModal({
|
||
content: err.message || "请求服务失败",
|
||
showCancel: false
|
||
});
|
||
});
|
||
},
|
||
/**
|
||
* 获取表单数据
|
||
* @param {Object} id
|
||
*/
|
||
getDetail(id) {
|
||
common_vendor.index.showLoading({
|
||
mask: true
|
||
});
|
||
db.collection(dbCollectionName).doc(id).field("content,root_id,author_id,parent_id,article_id,like_count,create_time,update_time,reply_count,ip_location").get().then((res) => {
|
||
const data = res.result.data[0];
|
||
if (data) {
|
||
this.formData = data;
|
||
}
|
||
}).catch((err) => {
|
||
common_vendor.index.showModal({
|
||
content: err.message || "请求服务失败",
|
||
showCancel: false
|
||
});
|
||
}).finally(() => {
|
||
common_vendor.index.hideLoading();
|
||
});
|
||
}
|
||
}
|
||
};
|
||
if (!Array) {
|
||
const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
|
||
const _easycom_uni_forms_item2 = common_vendor.resolveComponent("uni-forms-item");
|
||
const _easycom_uni_datetime_picker2 = common_vendor.resolveComponent("uni-datetime-picker");
|
||
const _component_undefined = common_vendor.resolveComponent("undefined");
|
||
const _easycom_uni_forms2 = common_vendor.resolveComponent("uni-forms");
|
||
(_easycom_uni_easyinput2 + _easycom_uni_forms_item2 + _easycom_uni_datetime_picker2 + _component_undefined + _easycom_uni_forms2)();
|
||
}
|
||
const _easycom_uni_easyinput = () => "../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js";
|
||
const _easycom_uni_forms_item = () => "../../uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.js";
|
||
const _easycom_uni_datetime_picker = () => "../../uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.js";
|
||
const _easycom_uni_forms = () => "../../uni_modules/uni-forms/components/uni-forms/uni-forms.js";
|
||
if (!Math) {
|
||
(_easycom_uni_easyinput + _easycom_uni_forms_item + _easycom_uni_datetime_picker + _easycom_uni_forms)();
|
||
}
|
||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||
return {
|
||
a: common_vendor.o(($event) => $data.formData.content = $event),
|
||
b: common_vendor.p({
|
||
modelValue: $data.formData.content
|
||
}),
|
||
c: common_vendor.p({
|
||
name: "content",
|
||
label: "评论内容",
|
||
required: true
|
||
}),
|
||
d: common_vendor.o(($event) => $data.formData.root_id = $event),
|
||
e: common_vendor.p({
|
||
placeholder: "根评论ID(0表示自身是根评论)",
|
||
modelValue: $data.formData.root_id
|
||
}),
|
||
f: common_vendor.p({
|
||
name: "root_id",
|
||
label: ""
|
||
}),
|
||
g: common_vendor.o(($event) => $data.formData.author_id = $event),
|
||
h: common_vendor.p({
|
||
placeholder: "作者ID(关联uni-id-users表)",
|
||
modelValue: $data.formData.author_id
|
||
}),
|
||
i: common_vendor.p({
|
||
name: "author_id",
|
||
label: "",
|
||
required: true
|
||
}),
|
||
j: common_vendor.o(($event) => $data.formData.parent_id = $event),
|
||
k: common_vendor.p({
|
||
placeholder: "父评论ID(0表示无父评论)",
|
||
modelValue: $data.formData.parent_id
|
||
}),
|
||
l: common_vendor.p({
|
||
name: "parent_id",
|
||
label: ""
|
||
}),
|
||
m: common_vendor.o(($event) => $data.formData.article_id = $event),
|
||
n: common_vendor.p({
|
||
placeholder: "关联文章ID",
|
||
modelValue: $data.formData.article_id
|
||
}),
|
||
o: common_vendor.p({
|
||
name: "article_id",
|
||
label: "",
|
||
required: true
|
||
}),
|
||
p: common_vendor.o(($event) => $data.formData.like_count = $event),
|
||
q: common_vendor.p({
|
||
placeholder: "点赞数",
|
||
type: "number",
|
||
modelValue: $data.formData.like_count
|
||
}),
|
||
r: common_vendor.p({
|
||
name: "like_count",
|
||
label: ""
|
||
}),
|
||
s: common_vendor.o(($event) => $data.formData.create_time = $event),
|
||
t: common_vendor.p({
|
||
["return-type"]: "timestamp",
|
||
modelValue: $data.formData.create_time
|
||
}),
|
||
v: common_vendor.p({
|
||
name: "create_time",
|
||
label: "",
|
||
required: true
|
||
}),
|
||
w: common_vendor.o(($event) => $data.formData.update_time = $event),
|
||
x: common_vendor.p({
|
||
["return-type"]: "timestamp",
|
||
modelValue: $data.formData.update_time
|
||
}),
|
||
y: common_vendor.p({
|
||
name: "update_time",
|
||
label: ""
|
||
}),
|
||
z: common_vendor.o(($event) => $data.formData.reply_count = $event),
|
||
A: common_vendor.p({
|
||
placeholder: "回复数",
|
||
type: "number",
|
||
modelValue: $data.formData.reply_count
|
||
}),
|
||
B: common_vendor.p({
|
||
name: "reply_count",
|
||
label: ""
|
||
}),
|
||
C: common_vendor.o(($event) => $data.formData.ip_location = $event),
|
||
D: common_vendor.p({
|
||
modelValue: $data.formData.ip_location
|
||
}),
|
||
E: common_vendor.p({
|
||
name: "ip_location",
|
||
label: ""
|
||
}),
|
||
F: common_vendor.o((...args) => $options.submit && $options.submit(...args)),
|
||
G: common_vendor.sr("form", "a2bac3b8-0"),
|
||
H: common_vendor.p({
|
||
model: $data.formData,
|
||
validateTrigger: "bind"
|
||
})
|
||
};
|
||
}
|
||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
||
wx.createPage(MiniProgramPage);
|
||
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/comment/edit.js.map
|