|
@@ -0,0 +1,252 @@
|
|
|
+<template>
|
|
|
+ <div class="container">
|
|
|
+ <h2 class="mb-4" id="formTitle">{{ formTitle }}</h2>
|
|
|
+ <el-form :model="form" ref="postForm" :rules="rules" label-width="120px">
|
|
|
+ <el-form-item label="选择公众号推文" prop="articleId">
|
|
|
+ <div class="bordered-content">
|
|
|
+ <el-radio-group v-model="form.articleId" @change="handleArticleChange" v-if="!loading && paginatedArticles.length">
|
|
|
+ <div v-for="article in paginatedArticles" :key="article.id" class="article-item">
|
|
|
+ <el-radio :label="article.id" :disabled="article.disabled">
|
|
|
+ {{ article.title }} - {{ article.date }}
|
|
|
+ </el-radio>
|
|
|
+ <hr v-if="$index !== paginatedArticles.length - 1" class="divider" />
|
|
|
+ </div>
|
|
|
+ </el-radio-group>
|
|
|
+ <div v-else-if="loading" class="text-center"><i class="el-icon-loading"></i></div>
|
|
|
+ <div v-else class="text-center">暂无文章</div>
|
|
|
+ </div>
|
|
|
+ <div class="pagination-container">
|
|
|
+ <el-pagination
|
|
|
+ v-if="!loading && paginatedArticles.length"
|
|
|
+ :current-page.sync="currentArticlePage"
|
|
|
+ :page-size="articlePageSize"
|
|
|
+ :total="allArticles.length"
|
|
|
+ layout="prev, pager, next"
|
|
|
+ @current-change="handleArticlePageChange"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="选择发送群组" prop="groupIds">
|
|
|
+ <div class="bordered-content group-container">
|
|
|
+ <el-checkbox-group v-model="form.groupIds" class="checkbox-group">
|
|
|
+ <div v-for="group in mockGroups" :key="group.id" class="group-item">
|
|
|
+ <el-checkbox :label="group.id">
|
|
|
+ {{ group.name }}
|
|
|
+ </el-checkbox>
|
|
|
+ </div>
|
|
|
+ </el-checkbox-group>
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="备注" prop="remarks">
|
|
|
+ <el-input v-model="form.remarks" type="textarea" :rows="3" resize="none" />
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item>
|
|
|
+ <div class="button-container">
|
|
|
+ <el-button @click="goBack">取消</el-button>
|
|
|
+ <el-button type="primary" @click="savePost(false)">保存</el-button>
|
|
|
+ <el-button type="success" @click="savePost(true)">发送</el-button>
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+export default {
|
|
|
+ name: 'WechatEdit',
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ accountId: this.$route.query.accountId || '',
|
|
|
+ postId: this.$route.query.postId || '',
|
|
|
+ currentArticlePage: 1,
|
|
|
+ articlePageSize: 5,
|
|
|
+ loading: false,
|
|
|
+ mockArticles: Array.from({ length: 15 }, (_, i) => ({
|
|
|
+ id: i + 1,
|
|
|
+ title: `文章${i + 1}`,
|
|
|
+ date: `2025-03-${String(i + 1).padStart(2, '0')}`,
|
|
|
+ disabled: false,
|
|
|
+ })),
|
|
|
+ mockGroups: [
|
|
|
+ { id: 1, name: '群组群组群组群组群组A' },
|
|
|
+ { id: 2, name: '群组B' },
|
|
|
+ { id: 3, name: '群组C' },
|
|
|
+ { id: 4, name: '群组D' },
|
|
|
+ { id: 5, name: '群组E' },
|
|
|
+ { id: 6, name: '群组F' },
|
|
|
+ { id: 7, name: '群组G' },
|
|
|
+ { id: 8, name: '群组H' },
|
|
|
+ { id: 9, name: '群组I' },
|
|
|
+ { id: 10, name: '群组J' },
|
|
|
+ { id: 11, name: '群组K' },
|
|
|
+ { id: 12, name: '群组L' },
|
|
|
+ { id: 13, name: '群组M' },
|
|
|
+ { id: 14, name: '群组N' },
|
|
|
+ { id: 15, name: '群组O' }, // 增加更多群组以测试滚动
|
|
|
+ ],
|
|
|
+ mockPosts: [],
|
|
|
+ form: {
|
|
|
+ articleId: '',
|
|
|
+ groupIds: [],
|
|
|
+ remarks: '',
|
|
|
+ },
|
|
|
+ rules: {
|
|
|
+ articleId: [{ required: true, message: '请选择一篇推文', trigger: 'change' }],
|
|
|
+ groupIds: [{ required: true, message: '请选择至少一个群组', trigger: 'change' }],
|
|
|
+ },
|
|
|
+ formTitle: '新建/编辑推文',
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ allArticles() {
|
|
|
+ console.log('allArticles:', this.mockArticles, 'length:', this.mockArticles?.length);
|
|
|
+ return this.mockArticles || [];
|
|
|
+ },
|
|
|
+ paginatedArticles() {
|
|
|
+ if (!this.allArticles || !Array.isArray(this.allArticles)) {
|
|
|
+ console.warn('allArticles is not an array:', this.allArticles);
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ const start = Math.max(0, (this.currentArticlePage - 1) * this.articlePageSize);
|
|
|
+ const end = Math.min(start + this.articlePageSize, this.allArticles.length);
|
|
|
+ const result = this.allArticles.slice(start, end);
|
|
|
+ console.log('paginatedArticles:', result, 'start:', start, 'end:', end);
|
|
|
+ return result;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ handleArticlePageChange(page) {
|
|
|
+ this.currentArticlePage = page;
|
|
|
+ },
|
|
|
+ handleArticleChange(value) {
|
|
|
+ console.log('Selected article ID:', value);
|
|
|
+ },
|
|
|
+ async loadFormData() {
|
|
|
+ this.loading = true;
|
|
|
+ try {
|
|
|
+ if (!this.accountId) {
|
|
|
+ this.$message.warning('未选择公众号');
|
|
|
+ this.$router.push('/');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.postId) {
|
|
|
+ this.formTitle = '编辑推文';
|
|
|
+ const post = this.mockPosts.find((p) => p.id === parseInt(this.postId));
|
|
|
+ if (post) {
|
|
|
+ this.form = {
|
|
|
+ articleId: post.articleId.toString(),
|
|
|
+ groupIds: post.groupIds.map((id) => id.toString()),
|
|
|
+ remarks: post.remarks || '',
|
|
|
+ };
|
|
|
+ this.mockArticles.forEach((article) => {
|
|
|
+ article.disabled = article.id === post.articleId;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载数据失败:', error);
|
|
|
+ this.$message.error('加载表单数据失败');
|
|
|
+ } finally {
|
|
|
+ this.loading = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async savePost(send = false) {
|
|
|
+ this.$refs['postForm'].validate(async (valid) => {
|
|
|
+ if (valid) {
|
|
|
+ try {
|
|
|
+ const postData = {
|
|
|
+ id: this.postId ? parseInt(this.postId) : this.mockPosts.length + 1,
|
|
|
+ accountId: parseInt(this.accountId),
|
|
|
+ articleId: parseInt(this.form.articleId),
|
|
|
+ groupIds: this.form.groupIds.map((id) => parseInt(id)),
|
|
|
+ remarks: this.form.remarks,
|
|
|
+ title: this.mockArticles.find((a) => a.id === parseInt(this.form.articleId)).title,
|
|
|
+ time: new Date().toISOString().slice(0, 10),
|
|
|
+ sender: '当前用户',
|
|
|
+ status: send ? '成功' : '待发送',
|
|
|
+ };
|
|
|
+
|
|
|
+ if (this.postId) {
|
|
|
+ const index = this.mockPosts.findIndex((p) => p.id === parseInt(this.postId));
|
|
|
+ this.mockPosts[index] = postData;
|
|
|
+ } else {
|
|
|
+ this.mockPosts.push(postData);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.$message.success(send ? '发送成功' : '保存成功');
|
|
|
+ this.goBack();
|
|
|
+ } catch (error) {
|
|
|
+ console.error('保存/发送失败:', error);
|
|
|
+ this.$message.error('操作失败');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$message.error('请填写完整表单');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ goBack() {
|
|
|
+ this.$router.push(`/huiju/wechatList?wcId=${this.accountId}`);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ console.log('Initial mockArticles:', this.mockArticles);
|
|
|
+ this.loadFormData();
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ '$route.query.accountId'(newId) {
|
|
|
+ this.accountId = newId || '';
|
|
|
+ },
|
|
|
+ '$route.query.postId'(newId) {
|
|
|
+ this.postId = newId || '';
|
|
|
+ this.loadFormData();
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+.container {
|
|
|
+ padding: 20px;
|
|
|
+}
|
|
|
+.bordered-content {
|
|
|
+ border: 1px solid #dcdfe6;
|
|
|
+ padding: 15px;
|
|
|
+ border-radius: 4px;
|
|
|
+}
|
|
|
+.article-item {
|
|
|
+ margin-bottom: 20px;
|
|
|
+}
|
|
|
+.article-item:last-child {
|
|
|
+ margin-bottom: 0;
|
|
|
+}
|
|
|
+.divider {
|
|
|
+ border: 0;
|
|
|
+ border-top: 1px solid #dcdfe6;
|
|
|
+ margin: 10px 0;
|
|
|
+}
|
|
|
+.pagination-container {
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
+ margin-top: 20px;
|
|
|
+}
|
|
|
+.group-container {
|
|
|
+ max-height: 500px; /* 设置最大高度 */
|
|
|
+ overflow-y: auto; /* 超过高度时显示滚动条 */
|
|
|
+}
|
|
|
+.checkbox-group {
|
|
|
+ display: flex;
|
|
|
+ flex-wrap: wrap; /* 自动换行 */
|
|
|
+ gap: 15px; /* 群组之间的间距 */
|
|
|
+}
|
|
|
+.group-item {
|
|
|
+ flex: 0 0 auto; /* 防止收缩 */
|
|
|
+}
|
|
|
+.button-container {
|
|
|
+ display: flex;
|
|
|
+ justify-content: flex-end;
|
|
|
+}
|
|
|
+</style>
|