Kaynağa Gözat

📦 feat(put/book): 投放书籍停止

晓晓晓晓丶vv 4 yıl önce
ebeveyn
işleme
c24cebc620

+ 8 - 0
src/api/index.ts

@@ -129,3 +129,11 @@ export const addDeliveryBook = (data: {
 export const logout = () => {
   return axios("/logout");
 };
+
+/**
+ * 停止投放书籍
+ * @param id 记录id
+ */
+export const onStopDeliveryBook = (id: number) => {
+  return axios("/stopDeliveryBook", { params: { id } });
+};

+ 5 - 0
src/components/confirm-button/index.vue

@@ -1,6 +1,7 @@
 <template>
   <div class="confirm-button">
     <a-button :type="type"
+              :disabled="disabled"
               @click.stop="onConfirm">{{label}}</a-button>
   </div>
 </template>
@@ -18,6 +19,10 @@ const ConfirmButton = defineComponent({
       type: String,
       default: "primary",
     },
+    disabled: {
+      type: Boolean,
+      default: false,
+    },
     confirmTitle: {
       type: String,
       default: "请确认您的操作",

+ 4 - 0
src/views/_pageOptions/table-put.ts

@@ -1,5 +1,9 @@
 export const TableColumnOfPutBooks = [
   {
+    title: "ID",
+    dataIndex: "id",
+  },
+  {
     title: "公众号名称",
     dataIndex: "official_name",
   },

+ 2 - 2
src/views/account/account.vue

@@ -70,9 +70,9 @@ const Account = defineComponent({
       onLoadOfficials();
     };
 
-    const onLoadOfficials = (query?: { page: number }) => {
+    const onLoadOfficials = (query?: { current: number }) => {
       let params = state.query;
-      if (query) params.page = query.page;
+      if (query) params.page = query.current;
       loading.value = true;
       getOfficialAccounts(params).then(({ data }) => {
         state.list = data.list;

+ 31 - 4
src/views/put/put-book.vue

@@ -12,7 +12,16 @@
              :pagination="tablePageOptions"
              :loading="loading"
              :columns="columns"
-             :data-source="list"></a-table>
+             :data-source="list"
+             @change="onBookLoaded">
+      <template #operator="{record}">
+        <confirm-button :label="record.status ? '停止' : '已停止'"
+                        :disabled="!record.status"
+                        type="link"
+                        confirm-content="确定要停止该条内容吗?"
+                        @click="onStop(record)" />
+      </template>
+    </a-table>
     <!-- 添加 -->
     <a-modal title="投放书籍添加"
              width="400px"
@@ -74,6 +83,7 @@ import {
 } from "vue";
 
 import ToolBar from "@/components/tool-bar/index.vue";
+import ConfirmButton from "@/components/confirm-button/index.vue";
 
 import useApp from "@/hooks/useApp";
 import usePagination from "@/hooks/usePagination";
@@ -81,13 +91,19 @@ import useFormLayout from "@/hooks/useFormLayout";
 import useDebounceFn from "@/hooks/useDebounceFn";
 import useValidate from "@/hooks/useValidate";
 
-import { getDeliveryBookList, getBooksByName, addDeliveryBook } from "@/api";
+import {
+  getDeliveryBookList,
+  getBooksByName,
+  addDeliveryBook,
+  onStopDeliveryBook,
+} from "@/api";
 import { TableColumnOfPutBooks } from "../_pageOptions/table-put";
 import { IBookSearchResult, IDeliveryBook } from "@/types/api";
 
 const PutBooks = defineComponent({
   components: {
     ToolBar,
+    ConfirmButton,
   },
   setup() {
     let { loading, meta, tablePageOptions } = usePagination();
@@ -121,14 +137,15 @@ const PutBooks = defineComponent({
       onBookLoaded();
     };
 
-    const onBookLoaded = async (query?: { page: 1 }) => {
+    const onBookLoaded = async (query?: { current: 1 }) => {
       try {
+        console.log(query);
         loading.value = true;
         const { official_name, book_name } = state;
         const { data } = await getDeliveryBookList({
           official_name,
           book_name,
-          page: query?.page ?? 1,
+          page: query?.current ?? 1,
         });
         state.list = data.list;
         meta.value = data.meta;
@@ -162,6 +179,7 @@ const PutBooks = defineComponent({
       onBookSearch,
       onSearch,
       onBookCheck,
+      onBookLoaded,
     };
   },
   methods: {
@@ -180,6 +198,7 @@ const PutBooks = defineComponent({
         );
         this.open = false;
         this.$message.success("添加成功");
+        this.onBookLoaded();
       } catch (error) {
         console.log("error while add delivery book");
         error.message && this.$message.error(error.message);
@@ -187,10 +206,18 @@ const PutBooks = defineComponent({
         this.addFormState.inConfirm = false;
       }
     },
+    onStop(data: IDeliveryBook) {
+      const { id } = data;
+      onStopDeliveryBook(id).then((_) => {
+        this.$message.success("停止成功");
+        this.onBookLoaded();
+      });
+    },
     onReset() {
       this.addFormState.official_id = "";
       this.addFormState.platform = "";
       this.addFormState.book = {};
+      this.addFormState.books = [];
     },
   },
 });