Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.

zako,zako~ #6

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions zaKo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
3 changes: 3 additions & 0 deletions zaKo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: site
site:
@(cd mock/ && make run) & npm run start
Binary file added zaKo/docs/imgs/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added zaKo/docs/imgs/img_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added zaKo/docs/imgs/img_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added zaKo/docs/imgs/img_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added zaKo/docs/imgs/toast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions zaKo/mock/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.exe
4 changes: 4 additions & 0 deletions zaKo/mock/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: run
run:
@go build -o mock.exe -v .
@./mock
99 changes: 99 additions & 0 deletions zaKo/mock/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package main

import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"strconv"
)

type UserUpdateReq struct {
StaffId string `json:"staff_id"`
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
Tags []string `json:"tags"`
}

func GetUsers(c *gin.Context) {
c.JSON(200, func() []User {
var userList []User
for _, user := range Users {
if user.Removed {
continue
}
userList = append(userList, user)
}
return userList
}())
}

func DeleteUser(c *gin.Context) {
id := c.Param("id")
if id == "" {
return
}
for idx, user := range Users {
if user.Id == id {
Users[idx].Removed = true
c.JSON(200, "ok")
return
}
}
}

func UpdateUser(c *gin.Context) {
id := c.Param("id")
if id == "" {
c.JSON(200, "user id is required")
}
var req UserUpdateReq
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(401, "param is wrong")
}
updateUser(id, &req)
c.JSON(200, "ok")
return
}

func updateUser(id string, u *UserUpdateReq) {
idx, _ := strconv.Atoi(id)
idx--
Users[idx].StaffId = u.StaffId
Users[idx].Name = u.Name
Users[idx].Phone = u.Phone
Users[idx].Email = u.Email
Users[idx].Tags = u.Tags
Users[idx].UpdateTime = getTime()
}

type NewUserReq struct {
StaffId string `json:"staff_id"`
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
Tags []string `json:"tags"`
}

func NewUser(c *gin.Context) {
var req NewUserReq
if c.ShouldBindJSON(&req) != nil {
c.JSON(401, "参数错误")
return
}
Users = append(Users, User{
Id: uuid.NewString(),
StaffId: req.StaffId,
Name: req.Name,
Phone: req.Phone,
Email: req.Email,
Tags: req.Tags,
UpdateTime: getTime(),
Removed: false,
})
c.Status(200)
}

func ResetDate(c *gin.Context) {
Users = append([]User(nil), backup...)
c.JSON(200, "用户已重置")
}
33 changes: 33 additions & 0 deletions zaKo/mock/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"github.com/gin-gonic/gin"
)

type LoginReq struct {
Username string `json:"username"`
Password string `json:"password"`
}

func Login(c *gin.Context) {
var req LoginReq
if err := c.ShouldBindJSON(&req); err != nil {
c.AbortWithStatusJSON(401, "参数错误")
}

if req.Username == "slime" && req.Password == "123456" {
c.JSON(200, gin.H{
"token": "927721",
"staff_id": "这是个8位学工号",
"name": "slime",
"role": "超级管理员",
})
} else {
c.JSON(200, gin.H{
"token": "",
"staff_id": "Unknown",
"name": "Unknown",
"role": "Unknown",
})
}
}
22 changes: 22 additions & 0 deletions zaKo/mock/cors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"github.com/gin-gonic/gin"
"net/http"
)

func AllowCors(c *gin.Context) {
method := c.Request.Method
origin := c.Request.Header.Get("Origin")
if origin != "" {
c.Header("Access-Control-Allow-Origin", "http://localhost:3000")
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type")
c.Header("Access-Control-Allow-Credentials", "true")
}
if method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
}
c.Next()
}
86 changes: 86 additions & 0 deletions zaKo/mock/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package main

import "time"

type User struct {
Id string `json:"id"`
StaffId string `json:"staff_id"`
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
Tags []string `json:"tags"`
UpdateTime string `json:"update_time"`
Removed bool `json:"-"`
}

// generated by ChatGPT-3.5

var Users = []User{
{"001", "001", "John Doe", "123-456-7890", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
{"002", "002", "Jane Smith", "987-654-3210", "[email protected]", []string{"tag2", "tag3"}, getTime(), false},
{"003", "003", "Alice Johnson", "555-555-5555", "[email protected]", []string{"tag1", "tag4"}, getTime(), false},
{"004", "004", "Bob Williams", "111-222-3333", "[email protected]", []string{"tag3", "tag5"}, getTime(), false},
{"005", "005", "Eva Davis", "444-555-6666", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
{"006", "006", "Michael Wilson", "777-888-9999", "[email protected]", []string{"tag4", "tag5"}, getTime(), false},
{"007", "007", "Olivia Brown", "333-222-1111", "[email protected]", []string{"tag2", "tag3"}, getTime(), false},
{"008", "008", "David Lee", "999-888-7777", "[email protected]", []string{"tag1", "tag5"}, getTime(), false},
{"009", "009", "Sophia Martin", "666-555-4444", "[email protected]", []string{"tag2", "tag4"}, getTime(), false},
{"010", "010", "James Anderson", "222-333-4444", "[email protected]", []string{"tag1", "tag3"}, getTime(), false},
{"011", "011", "Lily Martinez", "888-777-9999", "[email protected]", []string{"tag3", "tag5"}, getTime(), false},
{"012", "012", "William Moore", "111-111-1111", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
{"013", "013", "Ava Taylor", "444-444-4444", "[email protected]", []string{"tag4", "tag5"}, getTime(), false},
{"014", "014", "Michael Harris", "777-777-7777", "[email protected]", []string{"tag2", "tag3"}, getTime(), false},
{"015", "015", "Emma Clark", "222-222-2222", "[email protected]", []string{"tag1", "tag4"}, getTime(), false},
{"016", "016", "Daniel Young", "333-333-3333", "[email protected]", []string{"tag3", "tag5"}, getTime(), false},
{"017", "017", "Olivia Walker", "555-555-5555", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
{"018", "018", "Sophia Lewis", "666-666-6666", "[email protected]", []string{"tag2", "tag4"}, getTime(), false},
{"019", "019", "Ethan White", "888-888-8888", "[email protected]", []string{"tag1", "tag3"}, getTime(), false},
{"020", "020", "Ava Turner", "111-111-1111", "[email protected]", []string{"tag3", "tag5"}, getTime(), false},
{"021", "021", "Logan Hall", "222-222-2222", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
{"022", "022", "Mia Allen", "333-333-3333", "[email protected]", []string{"tag4", "tag5"}, getTime(), false},
{"023", "023", "Noah Scott", "444-444-4444", "[email protected]", []string{"tag2", "tag3"}, getTime(), false},
{"024", "024", "Isabella King", "555-555-5555", "[email protected]", []string{"tag1", "tag4"}, getTime(), false},
{"025", "025", "Liam Adams", "666-666-6666", "[email protected]", []string{"tag3", "tag5"}, getTime(), false},
{"026", "026", "Mia Wright", "777-777-7777", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
{"027", "027", "Jacob Green", "888-888-8888", "[email protected]", []string{"tag2", "tag4"}, getTime(), false},
{"028", "028", "Emily Turner", "999-999-9999", "[email protected]", []string{"tag1", "tag3"}, getTime(), false},
{"029", "029", "William Hall", "000-000-0000", "[email protected]", []string{"tag3", "tag5"}, getTime(), false},
{"030", "030", "Grace Allen", "123-123-1234", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
}

func getTime() string {
return time.Now().Format(time.DateTime)
}

var backup = []User{
{"001", "001", "John Doe", "123-456-7890", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
{"002", "002", "Jane Smith", "987-654-3210", "[email protected]", []string{"tag2", "tag3"}, getTime(), false},
{"003", "003", "Alice Johnson", "555-555-5555", "[email protected]", []string{"tag1", "tag4"}, getTime(), false},
{"004", "004", "Bob Williams", "111-222-3333", "[email protected]", []string{"tag3", "tag5"}, getTime(), false},
{"005", "005", "Eva Davis", "444-555-6666", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
{"006", "006", "Michael Wilson", "777-888-9999", "[email protected]", []string{"tag4", "tag5"}, getTime(), false},
{"007", "007", "Olivia Brown", "333-222-1111", "[email protected]", []string{"tag2", "tag3"}, getTime(), false},
{"008", "008", "David Lee", "999-888-7777", "[email protected]", []string{"tag1", "tag5"}, getTime(), false},
{"009", "009", "Sophia Martin", "666-555-4444", "[email protected]", []string{"tag2", "tag4"}, getTime(), false},
{"010", "010", "James Anderson", "222-333-4444", "[email protected]", []string{"tag1", "tag3"}, getTime(), false},
{"011", "011", "Lily Martinez", "888-777-9999", "[email protected]", []string{"tag3", "tag5"}, getTime(), false},
{"012", "012", "William Moore", "111-111-1111", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
{"013", "013", "Ava Taylor", "444-444-4444", "[email protected]", []string{"tag4", "tag5"}, getTime(), false},
{"014", "014", "Michael Harris", "777-777-7777", "[email protected]", []string{"tag2", "tag3"}, getTime(), false},
{"015", "015", "Emma Clark", "222-222-2222", "[email protected]", []string{"tag1", "tag4"}, getTime(), false},
{"016", "016", "Daniel Young", "333-333-3333", "[email protected]", []string{"tag3", "tag5"}, getTime(), false},
{"017", "017", "Olivia Walker", "555-555-5555", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
{"018", "018", "Sophia Lewis", "666-666-6666", "[email protected]", []string{"tag2", "tag4"}, getTime(), false},
{"019", "019", "Ethan White", "888-888-8888", "[email protected]", []string{"tag1", "tag3"}, getTime(), false},
{"020", "020", "Ava Turner", "111-111-1111", "[email protected]", []string{"tag3", "tag5"}, getTime(), false},
{"021", "021", "Logan Hall", "222-222-2222", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
{"022", "022", "Mia Allen", "333-333-3333", "[email protected]", []string{"tag4", "tag5"}, getTime(), false},
{"023", "023", "Noah Scott", "444-444-4444", "[email protected]", []string{"tag2", "tag3"}, getTime(), false},
{"024", "024", "Isabella King", "555-555-5555", "[email protected]", []string{"tag1", "tag4"}, getTime(), false},
{"025", "025", "Liam Adams", "666-666-6666", "[email protected]", []string{"tag3", "tag5"}, getTime(), false},
{"026", "026", "Mia Wright", "777-777-7777", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
{"027", "027", "Jacob Green", "888-888-8888", "[email protected]", []string{"tag2", "tag4"}, getTime(), false},
{"028", "028", "Emily Turner", "999-999-9999", "[email protected]", []string{"tag1", "tag3"}, getTime(), false},
{"029", "029", "William Hall", "000-000-0000", "[email protected]", []string{"tag3", "tag5"}, getTime(), false},
{"030", "030", "Grace Allen", "123-123-1234", "[email protected]", []string{"tag1", "tag2"}, getTime(), false},
}
36 changes: 36 additions & 0 deletions zaKo/mock/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module mock

go 1.21

require (
github.com/gin-gonic/gin v1.9.1
github.com/google/uuid v1.3.1
)

require (
github.com/bytedance/sonic v1.10.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.15.4 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.5.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading