2021年12月4日星期六

login.js

import {Button, Card, Form} from "react-bootstrap";
import {useContext, useState} from "react";
import axios from "axios";
import {server} from "../config";
import {resCode, successTime} from "../utils/util";
import {toast} from "react-toastify";
import {UserContext} from "../utils/userContenxt";
import Router from "next/router";
import jsCookie from "js-cookie";

const login = () => {
    const [uname, setUname] = useState('');
    const [pwd, setPwd] = useState('');
    const {user, setUser} = useContext(UserContext);

    async function submitLogin() {
        const res = await axios.post(`${server}/admin/login`, {uname: uname, pwd: pwd})
        const {code, msg, data} = await res.data
        if (resCode(code, msg)) return
        jsCookie.set('token', data.token)
        setUser(data)
        toast.success('登录成功', {autoClose: successTime})
        await Router.push("/")
    }

    return (
Login
用户名 setUname(event.target.value)}/> Password setPwd(event.target.value)}/>
) } export default login

_document.js

import Document, { Html, Head, Main, NextScript } from 'next/document'

class MyDocument extends Document {
  render() {
    return (
      
        
        
          
) } } export default MyDocument

_app.js


import '../styles/globals.css'
import 'bootstrap/dist/css/bootstrap.min.css';
import 'react-toastify/dist/ReactToastify.css';
import {Layout} from "../components/Layout";
import {ToastContainer} from "react-toastify";
import React, {useMemo} from "react";
import {SSRProvider} from "react-bootstrap";
import {UserContext} from "../utils/userContenxt";
import {useLocalStorage} from "../utils/data";


function MyApp({Component, pageProps}) {
    const [user, setUser] = useLocalStorage()
    const value = useMemo(() => ({user, setUser}), [user, setUser]);
    return 
        
            
                
                
            
        
    
}

export default MyApp

config/index.js

const dev = process.env.NODE_ENV !== 'production'
export const server = dev ? 'http://localhost:1211' : 'http://localhost:1211'

components/Layout.js

import Meta from "./Meta";
import {Container, Nav, Navbar, NavDropdown} from "react-bootstrap";
import {useContext} from "react";
import {UserContext} from "../utils/userContenxt";
import jsCookie from "js-cookie";
import Router from "next/router";

export const Layout = ({children}) => {
    const {user} = useContext(UserContext)
    if (user === undefined) return (<> {children} )
    const {menu} = user

    function handleLogout() {
        localStorage.removeItem('u')
        jsCookie.set('token', '')
        Router.push('/login')
    }

    return (<>
        
        
            
                React-Bootstrap
                
                
                    
                    
                
            
        
        
            {children}
        
    )
}

components/Meta.js

import Head from 'next/head'

const Meta = ({ title, keywords, description }) => {
  return (
    
      
      
      
      
      
      {title}
    
  )
}

Meta.defaultProps = {
  title: 'WebDev Newz',
  keywords: 'web development, programming',
  description: 'Get the latest news in web dev',
}

export default Meta

components/page.js

import {Badge, Button, ButtonGroup, Form, Pagination, Table} from "react-bootstrap";
import Router from "next/router";
import {getPathSearchParamObj} from "../utils/window";
import $ from 'jquery'

export const AddBtn = ({onClick}) => 
export const DataBaseBtn = ({handleShow, handleDel}) => (
    
    
)
export const DataStatus = ({status}) => status == 1 ? YES : NO
export const ModalBtn = ({handleClose, handleSubmit}) => (
    
    
)
export const OptionStatus = ({status}) => {
    return (
        <>
            
            
            
        
    )
}
export const SearchBtn = ({handleSearch, handleReset}) => {
    return (
        
            
            
        
    )
}
export const PageBreadcrumb = () => {
    return 

PageBreadcrumb

} export const PagePagination = ({page, pageSize, totalCount, totalPage}) => { return (
{ const paramObj = getPathSearchParamObj(); paramObj.pageSize = e.target.value const url = location.pathname + '?' + $.param(paramObj) Router.push(url) }} > { const paramObj = getPathSearchParamObj(); paramObj.page = page - 1 const url = location.pathname + '?' + $.param(paramObj) Router.push(url) }}/> { const paramObj = getPathSearchParamObj(); paramObj.page = page + 1 const url = location.pathname + '?' + $.param(paramObj) Router.push(url) }}/> Current:{page} TotalPage:{totalPage} TotalCount:{totalCount}
) } export const PageTable = ({children}) => { return ( {children}
) }

window.js

export const getPathSearchParamObj = () => {
    let url = location.search;
    let index = url.indexOf("?");
    url = url.substring(index + 1);
    let arr = url.split("&");
    let obj = {}
    for (let i = 0; i < arr.length; i++) {
        let arr1 = arr[i].split("=");
        obj[arr1[0]] = arr1[1];
    }
    return obj;
}

util.js

import {toast} from "react-toastify";
import Router from "next/router";
import {getPathSearchParamObj} from "./window";
import $ from 'jquery'

export const getQuery = (name) => {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    let r = window.location.search.substr(1).match(reg);
    if (r != null) return decodeURI(r[2]);
    return null;
}
export const isEmpty = (value) => {
    return value === '' || value === undefined
}

export const successTime = 2000
export const warningTime = 5000
export const errorTime = 5000
export const infoTime = 2000
export const resCode = (code, msg, tid) => {
    if (isEmpty(tid)) {
        switch (code) {
            case 3: // error
                toast.error(msg, {autoClose: errorTime})
                return true
            case 2: // warning
                toast.warning(msg, {autoClose: warningTime})
                return true
            case 1: // info
                toast.info(msg, {autoClose: infoTime})
                return false
            case 0:
                toast.success(msg, {autoClose: successTime})
                return false
            case -1:
                toast.error(msg, {autoClose: errorTime})
                return true
            case -2:
                toast.warning(msg, {autoClose: warningTime})
                Router.push('/login')
                return true
        }
    } else {
        switch (code) {
            case 3: // error
                toast.update(tid, {autoClose: errorTime, render: msg, type: "error", isLoading: false})
                return true
            case 2: // warning
                toast.update(tid, {autoClose: warningTime, render: msg, type: 'warning', isLoading: false})
                return true
            case 1: // info
                toast.update(tid, {autoClose: infoTime, render: msg, type: 'info', isLoading: false})
                return false
            case 0:
                toast.update(tid, {autoClose: successTime, render: msg, type: 'success', isLoading: false})
                return false
            case -1:
                toast.update(tid, {autoClose: errorTime, render: msg, type: 'error', isLoading: false})
                return true
            case -2:
                toast.update(tid, {autoClose: warningTime, render: msg, type: 'warning', isLoading: false})
                Router.push('/login')
                return true
        }
    }
}

export const refresh = () => {
    Router.push(location.pathname + '?' + $.param(getPathSearchParamObj()))
}

userContenxt.js

import {createContext} from "react";

export const UserContext = createContext({})

data.js

// Hook
import {useState} from "react";

export const useLocalStorage = (key, initialValue) => {
    // State to store our value
    // Pass initial state function to useState so logic is only executed once
    const [storedValue, setStoredValue] = useState(() => {
        try {
            // Get from local storage by key
            const item = window.localStorage.getItem(key);
            // Parse stored json or if none return initialValue
            return item ? JSON.parse(item) : initialValue;
        } catch (error) {
            // If error also return initialValue
            // console.log(error);
            return initialValue;
        }
    });
    // Return a wrapped version of useState's setter function that ...
    // ... persists the new value to localStorage.
    const setValue = (value) => {
        try {
            // Allow value to be a function so we have same API as useState
            const valueToStore = value instanceof Function ? value(storedValue) : value;
            // Save state
            setStoredValue(valueToStore);
            // Save to local storage
            window.localStorage.setItem(key, JSON.stringify(valueToStore));
        } catch (error) {
            // A more advanced implementation would handle the error case
            // console.log(error);
        }
    };
    return [storedValue, setValue];
}
export const getCookie = (name,cookie) => {
    const value = `; ${cookie}`;
    const parts = value.split(`; ${name}=`);
    if (parts.length === 2) return parts.pop().split(';').shift();
}

const.js

export const ConfirmMsg = 'Are you sure?'
export const DestinationUrl = '/login'
export const LoadingMsg = 'Loading...'

2021年12月3日星期五

4 Dec 2021

later 后来

 later 


defend辩护
defend,defend,defend,defend,defend
defend,defend,defend,defend,defend
defend,defend,defend,defend,defend
defend,defend,defend,defend,defend
How can you defend the killing of animals for pleasure
hardly强壮的
hardly,hardly,hardly,hardly,hardly
hardly,hardly,hardly,hardly,hardly
hardly,hardly,hardly,hardly,hardly
hardly,hardly,hardly,hardly,hardly
A few hardy people swam in the icy water
content 内容
content,content,content,content,content
content,content,content,content,content
content,content,content,content,content
content,content,content,content,content
I like the style of his writing but I don't like the content
Incapable 无能力的
incapable,incapable,incapable,incapable,incapable
incapable,incapable,incapable,incapable,incapable
incapable,incapable,incapable,incapable,incapable
incapable,incapable,incapable,incapable,incapable
These children seem to be totally incapable of working quietly by themselves
broadcast 广播
broadcast,broadcast,broadcast,broadcast,broadcast
broadcast,broadcast,broadcast,broadcast,broadcast
broadcast,broadcast,broadcast,broadcast,broadcast
broadcast,broadcast,broadcast,broadcast,broadcast
She broadcasts on current affairs.
fix 凝视
fix,fix,fix,fix,fix
fix,fix,fix,fix,fix
fix,fix,fix,fix,fix
fix,fix,fix,fix,fix
He fixed his eyes on the door
statement 陈述
statement,statement,statement,statement,statement
statement,statement,statement,statement,statement
statement,statement,statement,statement,statement
statement,statement,statement,statement,statement
Such a statement is useless
tight紧身的
tight,tight,tight,tight,tight
tight,tight,tight,tight,tight
tight,tight,tight,tight,tight
tight,tight,tight,tight,tight
This pair of trousers is too tight for me.
bath 沐浴
bath,bath,bath,bath,bath
bath,bath,bath,bath,bath
bath,bath,bath,bath,bath
bath,bath,bath,bath,bath
He takes a cold bath every day.
globe 地球
globe,globe,globe,globe,globe
globe,globe,globe,globe,globe
globe,globe,globe,globe,globe
globe,globe,globe,globe,globe
This plant can grow in many parts of the globe
aim 目的
aim,aim,aim,aim,aim
aim,aim,aim,aim,aim
aim,aim,aim,aim,aim
aim,aim,aim,aim,aim
He aimed the gun at the door
wherever 无论哪里
wherever,wherever,wherever,wherever,wherever
wherever,wherever,wherever,wherever,wherever
wherever,wherever,wherever,wherever,wherever
wherever,wherever,wherever,wherever,wherever
We'll go wherever you like
shade 阴影
shade,shade,shade,shade,shade
shade,shade,shade,shade,shade
shade,shade,shade,shade,shade
shade,shade,shade,shade,shade
There are no trees or bushes to give shade
hostess 女主人
hostess,hostess,hostess,hostess,hostess
hostess,hostess,hostess,hostess,hostess
hostess,hostess,hostess,hostess,hostess
hostess,hostess,hostess,hostess,hostess
The hostess made her guests comfortable.
attempt 企图
attempt,attempt,attempt,attempt,attempt
attempt,attempt,attempt,attempt,attempt
attempt,attempt,attempt,attempt,attempt
attempt,attempt,attempt,attempt,attempt
I would be the last to attempt to answer the question
ugly 丑陋
ugly,ugly,ugly,ugly,ugly
ugly,ugly,ugly,ugly,ugly
ugly,ugly,ugly,ugly,ugly
ugly,ugly,ugly,ugly,ugly
This is an ugly face
bug
There's a bug in my pencil-box
teeth 牙齿
teeth,teeth,teeth,teeth,teeth
teeth,teeth,teeth,teeth,teeth
teeth,teeth,teeth,teeth,teeth
teeth,teeth,teeth,teeth,teeth
People should clean their teeth every day.
clean
clean,clean,clean,clean,clean
clean,clean,clean,clean,clean
clean,clean,clean,clean,clean
clean,clean,clean,clean,clean
Please clean the window
jump
jump,jump,jump,jump.jump
jump,jump,jump,jump,jump
jump,jump,jump,jump,jump
jump,jump,jump,jump,jump
jump,jump,jump,jump,jump
Don't jump for the wall!

login.js