feat: 添加短信验证码发送记录功能
This commit is contained in:
@@ -33,8 +33,9 @@ func (ctl *orders) List(ctx fiber.Ctx, pagination *requests.Pagination, query *O
|
||||
}
|
||||
|
||||
// Refund
|
||||
// @Router /admin/orders/:id/refund [post]
|
||||
// @Bind id path
|
||||
//
|
||||
// @Router /admin/orders/:id/refund [post]
|
||||
// @Bind id path
|
||||
func (ctl *orders) Refund(ctx fiber.Ctx, id int64) error {
|
||||
order, err := model.OrdersModel().GetByID(ctx.Context(), id)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,15 +3,16 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"quyun/app/requests"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
_ "go.ipao.vip/atom"
|
||||
_ "go.ipao.vip/atom/contracts"
|
||||
. "go.ipao.vip/atom/fen"
|
||||
"quyun/app/requests"
|
||||
)
|
||||
|
||||
// @provider contracts.HttpRoute atom.GroupRoutes
|
||||
// @provider contracts.HttpRoute atom.GroupRoutes
|
||||
type Routes struct {
|
||||
log *log.Entry `inject:"false"`
|
||||
auth *auth
|
||||
|
||||
@@ -3,16 +3,17 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"quyun/app/model"
|
||||
"quyun/app/requests"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
_ "go.ipao.vip/atom"
|
||||
_ "go.ipao.vip/atom/contracts"
|
||||
. "go.ipao.vip/atom/fen"
|
||||
"quyun/app/model"
|
||||
"quyun/app/requests"
|
||||
)
|
||||
|
||||
// @provider contracts.HttpRoute atom.GroupRoutes
|
||||
// @provider contracts.HttpRoute atom.GroupRoutes
|
||||
type Routes struct {
|
||||
log *log.Entry `inject:"false"`
|
||||
auth *auth
|
||||
|
||||
@@ -16,9 +16,10 @@ type wechats struct {
|
||||
}
|
||||
|
||||
// GetJsSDK
|
||||
// @Router /wechats/js-sdk [get]
|
||||
// @Bind url query
|
||||
// @Bind user local
|
||||
//
|
||||
// @Router /wechats/js-sdk [get]
|
||||
// @Bind url query
|
||||
// @Bind user local
|
||||
func (ctl *wechats) GetJsSDK(ctx fiber.Ctx, url string, user *model.Users) (*wechat.JsSDK, error) {
|
||||
if user.AuthToken.Data.StableExpiresAt.Before(time.Now()) {
|
||||
token, err := ctl.wechat.RefreshAccessToken(user.AuthToken.Data.RefreshToken)
|
||||
|
||||
@@ -23,7 +23,150 @@ const docTemplate = `{
|
||||
},
|
||||
"host": "{{.Host}}",
|
||||
"basePath": "{{.BasePath}}",
|
||||
"paths": {},
|
||||
"paths": {
|
||||
"/admin/auth": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/medias": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/medias/{id}": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
},
|
||||
"delete": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/orders": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/orders/{id}/refund": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/posts": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
},
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/posts/{id}": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
},
|
||||
"put": {
|
||||
"responses": {}
|
||||
},
|
||||
"delete": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/posts/{id}/send-to/{userId}": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/statistics": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/uploads/post-uploaded-action": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/uploads/pre-uploaded-check/{md5}.{ext}": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/users": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/users/{id}": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/users/{id}/articles": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/users/{id}/balance": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/auth/login": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/auth/wechat": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/pay/callback/{channel}": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/posts": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/posts/mine": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/posts/{id}/buy": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/posts/{id}/play": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/posts/{id}/show": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/users/profile": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/users/username": {
|
||||
"put": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/wechats/js-sdk": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"BasicAuth": {
|
||||
"type": "basic"
|
||||
|
||||
@@ -17,7 +17,150 @@
|
||||
},
|
||||
"host": "localhost:8080",
|
||||
"basePath": "/api/v1",
|
||||
"paths": {},
|
||||
"paths": {
|
||||
"/admin/auth": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/medias": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/medias/{id}": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
},
|
||||
"delete": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/orders": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/orders/{id}/refund": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/posts": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
},
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/posts/{id}": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
},
|
||||
"put": {
|
||||
"responses": {}
|
||||
},
|
||||
"delete": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/posts/{id}/send-to/{userId}": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/statistics": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/uploads/post-uploaded-action": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/uploads/pre-uploaded-check/{md5}.{ext}": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/users": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/users/{id}": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/users/{id}/articles": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/admin/users/{id}/balance": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/auth/login": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/auth/wechat": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/pay/callback/{channel}": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/posts": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/posts/mine": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/posts/{id}/buy": {
|
||||
"post": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/posts/{id}/play": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/posts/{id}/show": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/users/profile": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/users/username": {
|
||||
"put": {
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/wechats/js-sdk": {
|
||||
"get": {
|
||||
"responses": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"BasicAuth": {
|
||||
"type": "basic"
|
||||
|
||||
@@ -15,7 +15,93 @@ info:
|
||||
termsOfService: http://swagger.io/terms/
|
||||
title: ApiDoc
|
||||
version: "1.0"
|
||||
paths: {}
|
||||
paths:
|
||||
/admin/auth:
|
||||
post:
|
||||
responses: {}
|
||||
/admin/medias:
|
||||
get:
|
||||
responses: {}
|
||||
/admin/medias/{id}:
|
||||
delete:
|
||||
responses: {}
|
||||
get:
|
||||
responses: {}
|
||||
/admin/orders:
|
||||
get:
|
||||
responses: {}
|
||||
/admin/orders/{id}/refund:
|
||||
post:
|
||||
responses: {}
|
||||
/admin/posts:
|
||||
get:
|
||||
responses: {}
|
||||
post:
|
||||
responses: {}
|
||||
/admin/posts/{id}:
|
||||
delete:
|
||||
responses: {}
|
||||
get:
|
||||
responses: {}
|
||||
put:
|
||||
responses: {}
|
||||
/admin/posts/{id}/send-to/{userId}:
|
||||
post:
|
||||
responses: {}
|
||||
/admin/statistics:
|
||||
get:
|
||||
responses: {}
|
||||
/admin/uploads/post-uploaded-action:
|
||||
post:
|
||||
responses: {}
|
||||
/admin/uploads/pre-uploaded-check/{md5}.{ext}:
|
||||
get:
|
||||
responses: {}
|
||||
/admin/users:
|
||||
get:
|
||||
responses: {}
|
||||
/admin/users/{id}:
|
||||
get:
|
||||
responses: {}
|
||||
/admin/users/{id}/articles:
|
||||
get:
|
||||
responses: {}
|
||||
/admin/users/{id}/balance:
|
||||
post:
|
||||
responses: {}
|
||||
/auth/login:
|
||||
get:
|
||||
responses: {}
|
||||
/auth/wechat:
|
||||
get:
|
||||
responses: {}
|
||||
/pay/callback/{channel}:
|
||||
post:
|
||||
responses: {}
|
||||
/posts:
|
||||
get:
|
||||
responses: {}
|
||||
/posts/{id}/buy:
|
||||
post:
|
||||
responses: {}
|
||||
/posts/{id}/play:
|
||||
get:
|
||||
responses: {}
|
||||
/posts/{id}/show:
|
||||
get:
|
||||
responses: {}
|
||||
/posts/mine:
|
||||
get:
|
||||
responses: {}
|
||||
/users/profile:
|
||||
get:
|
||||
responses: {}
|
||||
/users/username:
|
||||
put:
|
||||
responses: {}
|
||||
/wechats/js-sdk:
|
||||
get:
|
||||
responses: {}
|
||||
securityDefinitions:
|
||||
BasicAuth:
|
||||
type: basic
|
||||
|
||||
@@ -50,12 +50,20 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func() (*smsCodeSends, error) {
|
||||
obj := &smsCodeSends{}
|
||||
|
||||
return obj, nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func(
|
||||
auth *auth,
|
||||
medias *medias,
|
||||
middlewares *middlewares.Middlewares,
|
||||
orders *orders,
|
||||
posts *posts,
|
||||
smsCodeSends *smsCodeSends,
|
||||
statistics *statistics,
|
||||
uploads *uploads,
|
||||
users *users,
|
||||
@@ -66,6 +74,7 @@ func Provide(opts ...opt.Option) error {
|
||||
middlewares: middlewares,
|
||||
orders: orders,
|
||||
posts: posts,
|
||||
smsCodeSends: smsCodeSends,
|
||||
statistics: statistics,
|
||||
uploads: uploads,
|
||||
users: users,
|
||||
|
||||
@@ -30,6 +30,7 @@ type Routes struct {
|
||||
medias *medias
|
||||
orders *orders
|
||||
posts *posts
|
||||
smsCodeSends *smsCodeSends
|
||||
statistics *statistics
|
||||
uploads *uploads
|
||||
users *users
|
||||
@@ -149,6 +150,12 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
},
|
||||
Body[PostForm]("form"),
|
||||
))
|
||||
// Register routes for controller: smsCodeSends
|
||||
r.log.Debugf("Registering route: Get /admin/v1/sms-code-sends -> smsCodeSends.List")
|
||||
router.Get("/admin/v1/sms-code-sends"[len(r.Path()):], DataFunc1(
|
||||
r.smsCodeSends.List,
|
||||
Query[dto.SmsCodeSendListQuery]("query"),
|
||||
))
|
||||
// Register routes for controller: statistics
|
||||
r.log.Debugf("Registering route: Get /admin/v1/statistics -> statistics.statistics")
|
||||
router.Get("/admin/v1/statistics"[len(r.Path()):], DataFunc0(
|
||||
|
||||
61
backend_v1/app/http/admin/sms_code_sends.go
Normal file
61
backend_v1/app/http/admin/sms_code_sends.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"quyun/v2/app/http/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database"
|
||||
"quyun/v2/database/models"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type smsCodeSends struct{}
|
||||
|
||||
// List
|
||||
//
|
||||
// @Summary 短信验证码发送记录
|
||||
// @Tags Admin SMS
|
||||
// @Produce json
|
||||
// @Param query query dto.SmsCodeSendListQuery false "筛选条件"
|
||||
// @Success 200 {object} requests.Pager{items=models.SmsCodeSend} "成功"
|
||||
// @Router /admin/v1/sms-code-sends [get]
|
||||
// @Bind query query
|
||||
func (ctl *smsCodeSends) List(ctx fiber.Ctx, query *dto.SmsCodeSendListQuery) (*requests.Pager, error) {
|
||||
if query.Pagination == nil {
|
||||
query.Pagination = &requests.Pagination{}
|
||||
}
|
||||
query.Pagination.Format()
|
||||
|
||||
db := services.DB()
|
||||
if db == nil {
|
||||
return &requests.Pager{Pagination: *query.Pagination, Total: 0, Items: []*models.SmsCodeSend{}}, nil
|
||||
}
|
||||
|
||||
q := db.WithContext(ctx.Context()).Model(&models.SmsCodeSend{})
|
||||
if query.Phone != nil && *query.Phone != "" {
|
||||
q = q.Where("phone LIKE ?", database.WrapLike(*query.Phone))
|
||||
}
|
||||
|
||||
var total int64
|
||||
if err := q.Count(&total).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var items []*models.SmsCodeSend
|
||||
if err := q.
|
||||
Order("sent_at desc").
|
||||
Limit(int(query.Pagination.Limit)).
|
||||
Offset(int(query.Pagination.Offset())).
|
||||
Find(&items).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &requests.Pager{
|
||||
Pagination: *query.Pagination,
|
||||
Total: total,
|
||||
Items: items,
|
||||
}, nil
|
||||
}
|
||||
|
||||
10
backend_v1/app/http/dto/sms_code_send.go
Normal file
10
backend_v1/app/http/dto/sms_code_send.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package dto
|
||||
|
||||
import "quyun/v2/app/requests"
|
||||
|
||||
type SmsCodeSendListQuery struct {
|
||||
*requests.Pagination
|
||||
|
||||
Phone *string `query:"phone"`
|
||||
}
|
||||
|
||||
6
backend_v1/app/services/db.go
Normal file
6
backend_v1/app/services/db.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package services
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
func DB() *gorm.DB { return _db }
|
||||
|
||||
@@ -392,14 +392,25 @@ func (m *users) SendPhoneCode(ctx context.Context, phone string) error {
|
||||
}
|
||||
|
||||
// 生成/覆盖验证码:同一手机号再次发送时以最新验证码为准
|
||||
expiresAt := now.Add(5 * time.Minute)
|
||||
m.codeByPhone[phone] = phoneCodeEntry{
|
||||
code: code,
|
||||
expiresAt: now.Add(5 * time.Minute),
|
||||
expiresAt: expiresAt,
|
||||
}
|
||||
m.lastSentAtByPhone[phone] = now
|
||||
// log phone and code
|
||||
log.Infof("SendPhoneCode to %s: code=%s", phone, code)
|
||||
|
||||
if _db != nil {
|
||||
// 记录短信验证码发送日志(用于后台审计与排查)。
|
||||
_ = _db.WithContext(ctx).Create(&models.SmsCodeSend{
|
||||
Phone: phone,
|
||||
Code: code,
|
||||
SentAt: now,
|
||||
ExpiresAt: expiresAt,
|
||||
}).Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
CREATE TABLE sms_code_sends(
|
||||
id SERIAL8 PRIMARY KEY,
|
||||
phone varchar(20) NOT NULL,
|
||||
code varchar(20) NOT NULL,
|
||||
sent_at timestamp NOT NULL DEFAULT now(),
|
||||
expires_at timestamp NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX idx_sms_code_sends_phone ON sms_code_sends(phone);
|
||||
CREATE INDEX idx_sms_code_sends_sent_at ON sms_code_sends(sent_at);
|
||||
-- +goose StatementEnd
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DROP TABLE sms_code_sends;
|
||||
-- +goose StatementEnd
|
||||
|
||||
17
backend_v1/database/models/sms_code_send.go
Normal file
17
backend_v1/database/models/sms_code_send.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
const TableNameSmsCodeSend = "sms_code_sends"
|
||||
|
||||
// SmsCodeSend mapped from table <sms_code_sends>
|
||||
type SmsCodeSend struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
|
||||
Phone string `gorm:"column:phone;type:character varying(20);not null" json:"phone"`
|
||||
Code string `gorm:"column:code;type:character varying(20);not null" json:"code"`
|
||||
SentAt time.Time `gorm:"column:sent_at;type:timestamp without time zone;not null;default:now()" json:"sent_at"`
|
||||
ExpiresAt time.Time `gorm:"column:expires_at;type:timestamp without time zone;not null" json:"expires_at"`
|
||||
}
|
||||
|
||||
func (*SmsCodeSend) TableName() string { return TableNameSmsCodeSend }
|
||||
|
||||
@@ -33,6 +33,11 @@ const navItems = ref([
|
||||
icon: 'pi pi-shopping-cart',
|
||||
command: () => router.push('/orders')
|
||||
},
|
||||
{
|
||||
label: '短信认证',
|
||||
icon: 'pi pi-comment',
|
||||
command: () => router.push('/sms-code-sends')
|
||||
},
|
||||
{
|
||||
label: '设置',
|
||||
icon: 'pi pi-cog',
|
||||
|
||||
14
frontend/admin/src/api/smsCodeSendService.js
Normal file
14
frontend/admin/src/api/smsCodeSendService.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import httpClient from './httpClient';
|
||||
|
||||
export const smsCodeSendService = {
|
||||
get({ page = 1, limit = 10, phone = '' } = {}) {
|
||||
return httpClient.get('/sms-code-sends', {
|
||||
params: {
|
||||
page,
|
||||
limit,
|
||||
phone: phone.trim()
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
115
frontend/admin/src/pages/SmsCodeSendPage.vue
Normal file
115
frontend/admin/src/pages/SmsCodeSendPage.vue
Normal file
@@ -0,0 +1,115 @@
|
||||
<script setup>
|
||||
import { smsCodeSendService } from '@/api/smsCodeSendService';
|
||||
import { formatDate } from '@/utils/date';
|
||||
import Column from 'primevue/column';
|
||||
import DataTable from 'primevue/datatable';
|
||||
import InputText from 'primevue/inputtext';
|
||||
import ProgressSpinner from 'primevue/progressspinner';
|
||||
import Toast from 'primevue/toast';
|
||||
import { useToast } from 'primevue/usetoast';
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
const phone = ref('');
|
||||
const loading = ref(false);
|
||||
const searchTimeout = ref(null);
|
||||
|
||||
const records = ref({
|
||||
items: [],
|
||||
total: 0,
|
||||
page: 1,
|
||||
limit: 10
|
||||
});
|
||||
|
||||
const first = ref(0);
|
||||
const rows = ref(10);
|
||||
|
||||
const fetchRecords = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const currentPage = (first.value / rows.value) + 1;
|
||||
const resp = await smsCodeSendService.get({
|
||||
page: currentPage,
|
||||
limit: rows.value,
|
||||
phone: phone.value
|
||||
});
|
||||
records.value = resp.data;
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch sms code sends:', error);
|
||||
toast.add({ severity: 'error', summary: '错误', detail: '加载短信验证码记录失败', life: 3000 });
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const onPage = (event) => {
|
||||
first.value = event.first;
|
||||
rows.value = event.rows;
|
||||
fetchRecords();
|
||||
};
|
||||
|
||||
const onSearch = () => {
|
||||
if (searchTimeout.value) {
|
||||
clearTimeout(searchTimeout.value);
|
||||
}
|
||||
searchTimeout.value = setTimeout(() => {
|
||||
first.value = 0;
|
||||
fetchRecords();
|
||||
}, 300);
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
fetchRecords();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Toast />
|
||||
|
||||
<div class="w-full">
|
||||
<div class="flex justify-between items-center mb-6">
|
||||
<h1 class="text-2xl font-semibold text-gray-800">短信认证</h1>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="pb-10 flex gap-3 items-center">
|
||||
<InputText v-model="phone" placeholder="按手机号筛选..." class="flex-1" @input="onSearch" />
|
||||
</div>
|
||||
|
||||
<DataTable :value="records.items" :paginator="true" :rows="rows" :totalRecords="records.total"
|
||||
:loading="loading" :lazy="true" :first="first" @page="onPage"
|
||||
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
|
||||
:rowsPerPageOptions="[10, 25, 50]"
|
||||
currentPageReportTemplate="显示第 {first} 到 {last} 条,共 {totalRecords} 条结果" dataKey="id" stripedRows
|
||||
removableSort class="p-datatable-sm" responsiveLayout="scroll">
|
||||
|
||||
<template #empty>
|
||||
<div class="text-center p-4">暂无短信验证码记录。</div>
|
||||
</template>
|
||||
|
||||
<template #loading>
|
||||
<div class="flex flex-col items-center justify-center p-4">
|
||||
<ProgressSpinner style="width:50px;height:50px" />
|
||||
<span class="mt-2">加载短信验证码记录...</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<Column field="id" header="ID" sortable></Column>
|
||||
<Column field="phone" header="手机号" sortable></Column>
|
||||
<Column field="code" header="验证码" sortable></Column>
|
||||
<Column field="sent_at" header="发送时间" sortable>
|
||||
<template #body="{ data }">
|
||||
{{ formatDate(data.sent_at) }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="expires_at" header="过期时间" sortable>
|
||||
<template #body="{ data }">
|
||||
{{ formatDate(data.expires_at) }}
|
||||
</template>
|
||||
</Column>
|
||||
</DataTable>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -52,6 +52,11 @@ const routes = [
|
||||
name: 'Orders',
|
||||
component: () => import('./pages/OrderPage.vue'),
|
||||
},
|
||||
{
|
||||
path: '/sms-code-sends',
|
||||
name: 'SmsCodeSends',
|
||||
component: () => import('./pages/SmsCodeSendPage.vue'),
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
|
||||
Reference in New Issue
Block a user