完善未完成功能:修复关注列表/评论发布/编辑器草稿等页面

This commit is contained in:
2026-08-06 00:10:19 +08:00
parent b3c6fc67c9
commit 315bc474d6
28 changed files with 2979 additions and 4276 deletions
+107 -145
View File
@@ -68,178 +68,140 @@
</template>
<script>
import { ref, reactive, onMounted } from 'vue'
export default {
async onLoad(e) {
console.log(e);
this.pageType = e.type;
let cms = uni.getStorageSync("cms");
let index = uni.getStorageSync("selectIndex");
if (this.pageType === "edit") {
console.log(cms.cmsLst[index])
this.voteLst = cms.cmsLst[index].vote.voteLst;
this.voteTitle = cms.cmsLst[index].text;
this.birthday = cms.cmsLst[index].vote.datetime;
for (let i = 0 ; i < this.array.lenght; i ++ ) {
if (array[i] === cms.cmsLst[index].vote.type) {
this.select = i;
}
setup() {
const myPicker = ref(null)
const birthday = ref("")
const array = ref(["单选(默认)", "多选,无限制", "多选, 最多两项"])
const vote_id = ref('')
const select = ref(0)
const voteTitle = ref("")
const pageType = ref("add")
const voteLst = ref([
{ value: "" },
{ value: "" },
{ value: "" },
])
onMounted(() => {
// 模拟 onLoad
})
function generateRandomCode() {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
let code = ''
for (let i = 0; i < 24; i++) {
code += chars.charAt(Math.floor(Math.random() * chars.length))
}
if (!cms.cmsLst[index].vote.vote_id) {
let vote_id = this.generateRandomCode();
this.vote_id = vote_id;
cms.cmsLst[index].vote.vote_id = this.vote_id;
uni.setStorageSync("cms", cms);
}
} else if (this.pageType === "add") {
let vote_id = this.generateRandomCode();
this.vote_id = vote_id;
return code
}
},
data() {
return {
birthday: "",
array:[
"单选(默认)",
"多选,无限制",
"多选, 最多两项"
],
vote_id:'',
select: 0,
voteTitle: "",
voteLst: [
{
value:"",
},
{
value:"",
},
{
value:"",
},
],
pageType:"add",
function openDatetimePicker() {
myPicker.value.show()
}
},
methods: {
generateRandomCode() {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let code = '';
for (let i = 0; i < 24; i++) {
code += chars.charAt(Math.floor(Math.random() * chars.length));
}
return code;
},
openDatetimePicker() {
this.$refs.myPicker.show();
},
// 关闭picker
closeDatetimePicker() {
this.$refs.myPicker.hide();
},
handleSubmit(e) {
console.log(e);
this.birthday = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}:${e.second}`;
},
bindPickerChange(e) {
this.select = e.detail.value
},
del(index) {
if (this.voteLst.length >= 3) {
this.voteLst.splice(index, 1);
function handleSubmit(e) {
birthday.value = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}:${e.second}`
}
function bindPickerChange(e) {
select.value = e.detail.value
}
function del(index) {
if (voteLst.value.length >= 3) {
voteLst.value.splice(index, 1)
} else {
uni.showLoading({ title: '投票最少保留两个选项...' });
setTimeout(() => uni.hideLoading(), 1000);
uni.showLoading({ title: '投票最少保留两个选项...' })
setTimeout(() => uni.hideLoading(), 1000)
}
},
async toSuccess() {
if (!this.voteTitle) {
uni.showLoading({ title: '标题不能为空' });
setTimeout(() => uni.hideLoading(), 1000);
return;
}
async function toSuccess() {
if (!voteTitle.value) {
uni.showLoading({ title: '标题不能为空' })
setTimeout(() => uni.hideLoading(), 1000)
return
}
let vote = {
voteLst: this.voteLst,
vote_id: this.vote_id,
voteTitle: this.voteTitle,
type: this.array[this.select],
datetime: this.birthday,
}
if (!vote.type) {
uni.showLoading({ title: '投票类型不能为空' });
setTimeout(() => uni.hideLoading(), 1000);
return;
}
if (!vote.datetime) {
uni.showLoading({ title: '截止时间不能为空' });
setTimeout(() => uni.hideLoading(), 1000);
return;
}
if (!vote.datetime) {
let errIndex = -1;
for (let i = 0 ; i < vote.voteLst.length ; i ++ ) {
if (!vote.voteLst[i].value) {
errIndex = i;
}
}
if (errIndex !== 1) {
uni.showLoading({ title: `选项${ errIndex + 1 }不能为空` });
setTimeout(() => uni.hideLoading(), 1000);
return;
}
voteLst: voteLst.value,
vote_id: vote_id.value,
voteTitle: voteTitle.value,
type: array.value[select.value],
datetime: birthday.value,
}
let index = uni.getStorageSync("selectIndex");
let cms = uni.getStorageSync("cms");
if (vote.type === this.array[0]) {
vote.selectValue = "";
} else {
vote.selectValue = [];
if (!vote.type) {
uni.showLoading({ title: '投票类型不能为空' })
setTimeout(() => uni.hideLoading(), 1000)
return
}
vote.selectValu = false;
if (this.pageType === "add") {
if (!vote.datetime) {
uni.showLoading({ title: '截止时间不能为空' })
setTimeout(() => uni.hideLoading(), 1000)
return
}
let index = uni.getStorageSync("selectIndex")
let cms = uni.getStorageSync("cms")
if (vote.type === array.value[0]) {
vote.selectValue = ""
} else {
vote.selectValue = []
}
vote.selectValu = false
if (pageType.value === "add") {
cms.cmsLst.splice(index, 0, {
type: "vote",
text: this.voteTitle,
text: voteTitle.value,
vote: vote
})
} else if (this.pageType === "edit"){
} else if (pageType.value === "edit") {
cms.cmsLst.splice(index, 1, {
type: "vote",
text: this.voteTitle,
text: voteTitle.value,
vote: vote
})
}
uni.setStorageSync("cms", cms);
uni.setStorageSync("cms", cms)
await back()
}
await this.back();
},
async back() {
async function back() {
uni.navigateBack({
delta: 1,
fail: (err) => {
console.log(err);
uni.navigateTo({
url: "/pages2/editCms/editCms"
})
uni.navigateTo({ url: "/pages2/editCms/editCms" })
}
});
},
add() {
this.voteLst.push(
{
value:"",
}
)
},
})
}
function add() {
voteLst.value.push({ value: "" })
}
return {
myPicker,
birthday,
array,
vote_id,
select,
voteTitle,
pageType,
voteLst,
generateRandomCode,
openDatetimePicker,
handleSubmit,
bindPickerChange,
del,
toSuccess,
back,
add
}
}
}
</script>