Răsfoiți Sursa

文章默认状态

wenkai 2 săptămâni în urmă
părinte
comite
917a9e4002

+ 7 - 0
src/api/demo/demo/index.ts

@@ -60,3 +60,10 @@ export const delDemo = (id: string | number | Array<string | number>) => {
     method: 'delete'
   });
 };
+
+export const getAppScore = (eventId) => {
+  return request({
+    url: '/app/score/' + eventId,
+    method: 'get'
+  });
+};

+ 6 - 5
src/api/system/article/index.ts

@@ -63,12 +63,13 @@ export const delArticle = (id: string | number | Array<string | number>) => {
 };
 
 /**
- * 查询文章数量
- * @returns {*}
+ * 修改文章默认状态
+ * @param data - 文章BO对象
  */
-export const getArticleCount = () => {
+export const changeArticleDefault = (data: ArticleForm): AxiosPromise<void> => {
   return request({
-    url: '/system/article/count',
-    method: 'get'
+    url: '/system/article/changeArticleDefault',
+    method: 'post',
+    data: data
   });
 };

+ 10 - 12
src/api/system/article/types.ts

@@ -9,8 +9,6 @@ export interface ArticleVO {
    */
   eventId: string | number;
 
-  eventName: string;
-
   /**
    * 标题
    */
@@ -26,6 +24,11 @@ export interface ArticleVO {
    */
   type: number;
 
+  /**
+   * 是否默认 1:默认
+   */
+  isDefault: number;
+
   /**
    * 是否展示 0:展示 1:隐藏
    */
@@ -43,11 +46,6 @@ export interface ArticleForm extends BaseEntity {
    */
   eventId?: string | number;
 
-  /**
-   * 赛事名称
-   */
-  eventName?:string;
-
   /**
    * 标题
    */
@@ -63,6 +61,11 @@ export interface ArticleForm extends BaseEntity {
    */
   type?: number;
 
+  /**
+   * 是否默认 1:默认
+   */
+  isDefault?: number;
+
   /**
    * 是否展示 0:展示 1:隐藏
    */
@@ -75,11 +78,6 @@ export interface ArticleQuery extends PageQuery {
    */
   eventId?: string | number;
 
-  /**
-   * 赛事名称
-   */
-  eventName?:string;
-
   /**
    * 标题
    */

+ 9 - 7
src/views/demo/demo/index.vue

@@ -23,18 +23,18 @@
       <template #header>
         <el-row :gutter="10" class="mb8">
           <el-col :span="1.5">
-            <el-button v-hasPermi="['demo:demo:add']" type="primary" plain icon="Plus" @click="handleAdd">新增</el-button>
+            <el-button v-hasPermi="['demo:demo:add']" type="primary" plain icon="Plus" @click="handleAdd">新增 </el-button>
           </el-col>
           <el-col :span="1.5">
-            <el-button v-hasPermi="['demo:demo:edit']" type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()">修改</el-button>
+            <el-button v-hasPermi="['demo:demo:edit']" type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()">修改 </el-button>
           </el-col>
           <el-col :span="1.5">
             <el-button v-hasPermi="['demo:demo:remove']" type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()"
-              >删除</el-button
-            >
+              >删除
+            </el-button>
           </el-col>
           <el-col :span="1.5">
-            <el-button v-hasPermi="['demo:demo:export']" type="warning" plain icon="Download" @click="handleExport">导出</el-button>
+            <el-button v-hasPermi="['demo:demo:export']" type="warning" plain icon="Download" @click="handleExport"> 导出 </el-button>
           </el-col>
           <right-toolbar v-model:show-search="showSearch" @query-table="getList"></right-toolbar>
         </el-row>
@@ -92,7 +92,7 @@
 </template>
 
 <script setup name="Demo" lang="ts">
-import { listDemo, getDemo, delDemo, addDemo, updateDemo } from '@/api/demo/demo';
+import { listDemo, getDemo, delDemo, addDemo, updateDemo, getAppScore } from "@/api/demo/demo";
 import { DemoVO, DemoQuery, DemoForm } from '@/api/demo/demo/types';
 
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
@@ -239,7 +239,9 @@ const handleExport = () => {
   );
 };
 
-onMounted(() => {
+onMounted(async () => {
   getList();
+  const res = await getAppScore(1);
+  console.log(res);
 });
 </script>

+ 30 - 66
src/views/system/activityIntroduction/index.vue

@@ -7,11 +7,6 @@
             <!--            <el-form-item label="赛事id" prop="eventId">-->
             <!--              <el-input v-model="queryParams.eventId" placeholder="请输入赛事id" clearable @keyup.enter="handleQuery" />-->
             <!--            </el-form-item>-->
-            <el-form-item label="赛事名称" prop="eventName">
-              <el-select v-model="queryParams.eventName" placeholder="请选择赛事" clearable>
-                <el-option v-for="event in eventOptions" :key="event.eventId" :label="event.eventName" :value="event.eventName" />
-              </el-select>
-            </el-form-item>
             <el-form-item label="标题" prop="title">
               <el-input v-model="queryParams.title" placeholder="请输入标题" clearable @keyup.enter="handleQuery" />
             </el-form-item>
@@ -59,9 +54,8 @@
 
       <el-table v-loading="loading" border :data="articleList" @selection-change="handleSelectionChange">
         <el-table-column type="selection" width="55" align="center" />
-        <el-table-column label="id" align="center" prop="id" v-if="true" />
+        <el-table-column label="" align="center" prop="id" v-if="true" />
         <el-table-column label="赛事id" align="center" prop="eventId" />
-        <el-table-column label="赛事名称" align="center" prop="eventName" />
         <el-table-column label="标题" align="center" prop="title" />
         <!--        <el-table-column label="内容" align="center" prop="content" />-->
         <el-table-column label="文章类型" align="center" prop="type">
@@ -69,16 +63,18 @@
             <dict-tag :options="article_type" :value="scope.row.type" />
           </template>
         </el-table-column>
-        <el-table-column label="是否展示" align="center" prop="status">
+        <el-table-column label="是否默认 1:默认" align="center" prop="isDefault">
+          <template #default="scope">
+            <el-switch v-model="scope.row.isDefault" :active-value="1" :inactive-value="0" @change="handleDefaultChange(scope.row)"></el-switch>
+          </template>
+        </el-table-column>
+        <el-table-column label="是否展示 0:展示 1:隐藏" align="center" prop="status">
           <template #default="scope">
             <dict-tag :options="article_status" :value="scope.row.status" />
           </template>
         </el-table-column>
         <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
           <template #default="scope">
-            <el-tooltip content="查看" placement="top">
-              <el-button link type="primary" icon="View" @click="handleView(scope.row)" v-hasPermi="['system:article:view']"></el-button>
-            </el-tooltip>
             <el-tooltip content="修改" placement="top">
               <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:article:edit']"></el-button>
             </el-tooltip>
@@ -94,31 +90,29 @@
     <!-- 添加或修改文章对话框 -->
     <el-dialog :title="dialog.title" v-model="dialog.visible" width="1200px" append-to-body>
       <el-form ref="articleFormRef" :model="form" :rules="rules" label-width="80px">
-        <el-form-item label="赛事" prop="eventId">
-          <el-select v-model="form.eventId" placeholder="请选择赛事" clearable :disabled="isViewMode">
-            <el-option v-for="event in eventOptions" :key="event.eventId" :label="event.eventName" :value="event.eventId" />
-          </el-select>
+        <el-form-item label="赛事id" prop="eventId">
+          <el-input v-model="form.eventId" placeholder="请输入赛事id" />
         </el-form-item>
         <el-form-item label="标题" prop="title">
-          <el-input v-model="form.title" placeholder="请输入标题" :disabled="isViewMode" />
+          <el-input v-model="form.title" placeholder="请输入标题" />
         </el-form-item>
         <el-form-item label="内容">
-          <editor v-model="form.content" :min-height="192" :readOnly="isViewMode" />
+          <editor v-model="form.content" :min-height="192" />
         </el-form-item>
         <el-form-item label="文章类型" prop="type">
-          <el-select v-model="form.type" placeholder="请选择文章类型" :disabled="isViewMode">
+          <el-select v-model="form.type" placeholder="请选择文章类型">
             <el-option v-for="dict in article_type" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"></el-option>
           </el-select>
         </el-form-item>
         <el-form-item label="是否展示" prop="status">
-          <el-radio-group v-model="form.status" :disabled="isViewMode">
+          <el-radio-group v-model="form.status">
             <el-radio v-for="dict in article_status" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
           </el-radio-group>
         </el-form-item>
       </el-form>
       <template #footer>
         <div class="dialog-footer">
-          <el-button v-if="!isViewMode" :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
+          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
           <el-button @click="cancel">取 消</el-button>
         </div>
       </template>
@@ -127,18 +121,11 @@
 </template>
 
 <script setup name="Article" lang="ts">
-import { listArticle, getArticle, delArticle, addArticle, updateArticle } from '@/api/system/article';
+import { listArticle, getArticle, delArticle, addArticle, updateArticle, changeArticleDefault } from '@/api/system/article';
 import { ArticleVO, ArticleQuery, ArticleForm } from '@/api/system/article/types';
-import { getEventIdNameMap } from '@/api/system/gameEvent';
-
-// 定义事件选项接口
-interface EventOption {
-  eventId: string | number;
-  eventName: string;
-}
 
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
-const { article_status, article_type } = toRefs<any>(proxy?.useDict('article_status', 'article_type'));
+const { article_status, article_type, is_default } = toRefs<any>(proxy?.useDict('article_status', 'article_type', 'is_default'));
 
 const articleList = ref<ArticleVO[]>([]);
 const buttonLoading = ref(false);
@@ -148,7 +135,6 @@ const ids = ref<Array<string | number>>([]);
 const single = ref(true);
 const multiple = ref(true);
 const total = ref(0);
-const eventOptions = ref<EventOption[]>([]);
 
 const queryFormRef = ref<ElFormInstance>();
 const articleFormRef = ref<ElFormInstance>();
@@ -158,16 +144,14 @@ const dialog = reactive<DialogOption>({
   title: ''
 });
 
-// 添加查看模式状态
-const isViewMode = ref(false);
-
 const initFormData: ArticleForm = {
   id: undefined,
   eventId: undefined,
   title: undefined,
   content: undefined,
   type: undefined,
-  status: '0'
+  isDefault: undefined,
+  status: undefined
 };
 const data = reactive<PageData<ArticleForm, ArticleQuery>>({
   form: { ...initFormData },
@@ -175,11 +159,12 @@ const data = reactive<PageData<ArticleForm, ArticleQuery>>({
     pageNum: 1,
     pageSize: 10,
     eventId: undefined,
-    eventName: undefined,
     title: undefined,
     content: undefined,
     type: undefined,
     status: undefined,
+    orderByColumn: undefined,
+    isAsc: undefined,
     params: {}
   },
   rules: {
@@ -205,7 +190,6 @@ const getList = async () => {
 /** 取消按钮 */
 const cancel = () => {
   reset();
-  isViewMode.value = false;
   dialog.visible = false;
 };
 
@@ -237,7 +221,6 @@ const handleSelectionChange = (selection: ArticleVO[]) => {
 /** 新增按钮操作 */
 const handleAdd = () => {
   reset();
-  isViewMode.value = false;
   dialog.visible = true;
   dialog.title = '添加文章';
 };
@@ -248,21 +231,10 @@ const handleUpdate = async (row?: ArticleVO) => {
   const _id = row?.id || ids.value[0];
   const res = await getArticle(_id);
   Object.assign(form.value, res.data);
-  isViewMode.value = false;
   dialog.visible = true;
   dialog.title = '修改文章';
 };
 
-const handleView = async (row?: ArticleVO) => {
-  reset();
-  const _id = row?.id || ids.value[0];
-  const res = await getArticle(_id);
-  Object.assign(form.value, res.data);
-  isViewMode.value = true;
-  dialog.visible = true;
-  dialog.title = '查看文章';
-};
-
 /** 提交按钮 */
 const submitForm = () => {
   articleFormRef.value?.validate(async (valid: boolean) => {
@@ -300,29 +272,21 @@ const handleExport = () => {
   );
 };
 
-/** 获取赛事选项数据 */
-const getEventOptions = async () => {
+/** 默认状态修改  */
+const handleDefaultChange = async (row: ArticleVO) => {
+  const text = row.isDefault === 1 ? '设为默认' : '取消默认';
   try {
-    const res = await getEventIdNameMap();
-    console.log('查询赛事名称和id的map:', res);
-    // 根据实际返回的数据结构处理
-    if (res.data && typeof res.data === 'object') {
-      eventOptions.value = Object.entries(res.data).map(([eventName, eventId]) => ({
-        eventId: eventId as string | number,
-        eventName: eventName
-      }));
-    } else {
-      eventOptions.value = [];
-    }
-    console.log('赛事选项数据:', eventOptions.value);
-  } catch (error) {
-    console.error('获取赛事数据失败:', error);
-    eventOptions.value = [];
+    await proxy?.$modal.confirm('确认要"' + text + '""' + row.title + '"吗?');
+    await changeArticleDefault(row);
+    await getList();
+    proxy?.$modal.msgSuccess(text + '成功');
+  } catch {
+    // 如果用户取消操作,恢复原始值
+    row.isDefault = row.isDefault === 1 ? 0 : 1;
   }
 };
 
 onMounted(() => {
   getList();
-  getEventOptions();
 });
 </script>