first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
class Http {
defaultOption = {
timeout: 6000,
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
}
constructor() {
this.xhr = new XMLHttpRequest()
}
get(par) {
return new Promise((success, error) => {
this.setOption(par)
let urlParams = ""
for (const key in par.data) {
urlParams += `&${key}=${par.data[key]}`
}
urlParams = urlParams.replace("&", "")
this.xhr.open("GET", `${par.url}?${urlParams}`)
this.xhr.timeout = this.defaultOption.timeout
this.setHeader(par.headers)
this.xhr.send()
this.statechange(success, error);
})
}
post(par) {
return new Promise((success, error) => {
this.setOption(par)
this.xhr.open("POST", par.url)
this.xhr.timeout = this.defaultOption.timeout
this.setHeader(par.headers)
this.xhr.send(JSON.stringify(par.data))
this.statechange(success, error);
})
}
setOption(par) {
this.defaultOption.timeout = par.timeout || this.defaultOption.timeout
// ....
}
setHeader(headerObject = {}) {
Object.assign(headerObject, this.defaultOption.headers)
for (const key in headerObject) {
this.xhr.setRequestHeader(key, headerObject[key]);
}
}
statechange(success, error) {
this.xhr.onreadystatechange = () => {
if (this.xhr.readyState == 4) {
if (this.xhr.status == 200) {
let data = JSON.parse(this.xhr.response)
success(data.result)
} else {
error(this.xhr)
}
}
}
}
}
var http = new Http();

View File

@@ -0,0 +1,84 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body,li{
margin: 0;
padding: 0;
list-style: none;
}
ul {
display: flex;
flex-wrap: wrap;
}
li {
width: 20%;
margin-bottom: 30px;
}
li img {
width: 100%;
}
</style>
</head>
<body>
<ul>
</a>
</ul>
<button>点我</button>
<div class="result"></div>
</body>
<script src="./http.js"></script>
<script>
let page = 1, total_page = 0;
let getList = async () => {
let res = await http.get({
url: 'http://127.0.0.1:3000/api/json/classList',
data: {
id: 253,
page
}
});
total_page = res.total_page
renderPage(res)
}
let renderPage = (res) => {
res.data.forEach(v => {
$("ul").innerHTML += `
<li>
<a target="_blank" href="./info.html?id=${v.id}&total=${v.total}">
<img src="${v.preview}" alt="">
<p>${v.title}</p>
</a>
</li>`
});
}
$("button").onclick = () => {
page +=1;
if (page <= total_page) {
getList()
} else {
$(".result").innerText = "没有数据了"
}
}
getList()
function $(className) {
return document.querySelector(className);
}
</script>
</html>

View File

@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body,
li {
margin: 0;
padding: 0;
list-style: none;
}
img {
width: 100%;
}
</style>
</head>
<body>
<div class="info">
</div>
</body>
<script src="./http.js"></script>
<script>
let getInfo = async () => {
let res = await http.get({
url: 'http://127.0.0.1:3000/api/json/info',
data: {
id: query("id"),
quantity: query("total")
}
});
renderPage(res)
}
let renderPage = (res) => {
console.log(res);
res.forEach(v => {
$(".info").innerHTML += `
<img src="${v}" alt="">
`
});
}
getInfo()
function query(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null)
return unescape(r[2]);
return null;
}
function $(className) {
return document.querySelector(className);
}
</script>
</html>

View File

@@ -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*

View File

@@ -0,0 +1,70 @@
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
The page will reload when you make changes.\
You may also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
### Analyzing the Bundle Size
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
### Making a Progressive Web App
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
### Advanced Configuration
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
### Deployment
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
### `npm run build` fails to minify
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
{
"name": "hello-react",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.2",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

View File

@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

View File

@@ -0,0 +1,24 @@
import {Link,Route} from 'react-router-dom';
import Index from './page/index/index';
import About from './page/about/about';
function App() {
return (
<div className="App">
react 学习
<div className="nav">
<Link to="/index">index</Link>
<Link to="/about">about</Link>
</div>
<div className="main">
<Route path="/index" component={Index}></Route>
<Route path="/about" component={About}></Route>
</div>
</div>
);
}
export default App;

View File

@@ -0,0 +1,15 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
// import './index.css';
import App from './App';
import {BrowserRouter} from 'react-router-dom'
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</React.StrictMode>
);

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

View File

@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>tabs切换</title>
<style>
body,ul,li {
margin: 0;
padding: 0;
list-style: none;
}
.title {
display: flex;
}
.title li {
margin-right: 15px;
cursor: pointer;
}
.title .active {
color: red;
}
.content li {
display: none;
}
.content .active {
display: block !important;
}
</style>
</head>
<body>
<ul class="title">
<li class="active">社会</li>
<li>经济</li>
<li>体育</li>
<li>科技</li>
</ul>
<ul class="content">
<li class="active">社会 的内容</li>
<li>经济 的内容</li>
<li>体育 的内容</li>
<li>科技 的内容</li>
</ul>
</body>
<script>
let titleLi = document.querySelectorAll(".title li");
let contentLi = document.querySelectorAll(".content li");
titleLi.forEach(function(v,i) {
v.onclick = function () {
titleLi.forEach(function(val,index) {
val.className = ""
contentLi[index].className = ""
})
v.className = "active"
contentLi[i].className = "active"
}
})
</script>
</html>

View File

@@ -0,0 +1,141 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>tabs切换 V2</title>
<style>
body,
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
.title {
display: flex;
}
.title li {
margin-right: 15px;
cursor: pointer;
}
.title .active {
color: red;
}
.content li {
display: none;
}
.content .active {
display: block !important;
}
</style>
</head>
<body>
<ul class="title"></ul>
<ul class="content"></ul>
</body>
<script>
// 发送ajax请求获取这个数组
let data = [
{
id: 1,
title: '社会',
content: [
{ text: '社会的内容1' },
{ text: '社会的内容2' },
{ text: '社会的内容3' }
]
},
{
id: 2,
title: '经济',
content: [
{ text: '经济 的内容1' },
{ text: '经济 的内容2' },
{ text: '经济 的内容3' },
{ text: '经济 的内容4' },
]
},
{
id: 3,
title: '体育',
content: [
{ text: '体育 的内容1' },
{ text: '体育 的内容2' }
]
},
{
id: 4,
title: '科技',
content: [
{ text: '科技 的内容1' },
{ text: '科技 的内容2' },
{ text: '科技 的内容3' },
]
}
];
let title = $(".title"), content = $(".content");
function renderPage() {
data.forEach(function (v, i) {
title.innerHTML += `<li class="${i == 0 ? 'active' : ''}">${v.title}</li>`;
content.innerHTML +=
`<li class="${i == 0 ? 'active' : ''}">
${
v.content.map(function (item) {
return `<p>${item.text}</p>`
})
}
</li>`;
})
bindClcik();
}
function bindClcik() {
let titleLi = _(".title li"), contentLi = _(".content li");
titleLi.forEach(function (v, i) {
v.onclick = function () {
titleLi.forEach(function (val, index) {
val.className = ""
contentLi[index].className = ""
})
v.className = "active"
contentLi[i].className = "active"
}
})
}
Array.prototype.map = function (callback) {
let result = []
for (let index = 0; index < this.length; index++) {
result.push(callback(this[index], index, this))
}
return result.toString().replaceAll(",", "");
}
renderPage()
function $(className) {
return document.querySelector(className);
}
function _(className) {
return document.querySelectorAll(className);
}
</script>
</html>

View File

@@ -0,0 +1,200 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>侧滑</title>
<style>
body,
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
ul {
overflow: hidden;
}
li {
display: flex;
align-items: center;
height: 50px;
border-bottom: 1px solid #ebe8e8;
padding: 0 10px;
box-sizing: border-box;
font-size: 14px;
position: relative;
}
.action {
color: #fff;
font-size: 14px;
width: 165px;
display: flex;
height: 100%;
position: absolute;
right: -165px;
}
.action div {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
}
.action .top {
background: #009bfe;
}
.action .read {
background: #fe8d3f;
}
.action .delt {
background: #ff5967;
}
</style>
</head>
<body>
<ul>
<li>
测试1
<div class="action">
<div class="top">置顶</div>
<div class="read">未读</div>
<div class="delt">删除</div>
</div>
</li>
<li>
测试2
<div class="action">
<div class="top">置顶</div>
<div class="read">未读</div>
<div class="delt">删除</div>
</div>
</li>
<li>
测试3
<div class="action">
<div class="top">置顶</div>
<div class="read">未读</div>
<div class="delt">删除</div>
</div>
</li>
</ul>
</body>
<script>
// 0 关闭状态 -165 打开状态
let startX = 0, leftXArr = [];
_("ul li").forEach(function (v, i) {
v.ontouchstart = function (e) {
startX = e.touches[0].clientX
_("ul li").forEach(function (item, j) {
if (i != j) {
item.style = `
transform: translateX(0px);
`
}
})
}
v.ontouchmove = function (e) {
let moveX = e.touches[0].clientX
// 左滑moveX 小于 startX 右滑 大于
// 左滑
if (determineDirection(moveX, startX)) {
// console.log("左滑: ", moveX);
let currentX = v.style.transform.replace(/[^0-9]/ig, '')
if (-currentX != -165) {
console.log(222);
v.style = `
transform: translateX(-${startX - moveX > 165 ? '165' : startX - moveX}px);
`
} else {
leftXArr.push(moveX)
console.log("leftXArr: ", leftXArr);
if (leftXArr[leftXArr.length - 1] > leftXArr[leftXArr.length - 2]) {
leftXArr = []
console.log("左边的右滑动");
let x = -165 + (leftXArr[leftXArr.length - 1] - leftXArr[0]);
v.style = `
transform: translateX(${x}px);
`
} else {
console.log("左边的左滑动");
}
}
v.open = true
} else {
console.log("右滑");
if (v.open) {
let x = -165 + (moveX - startX);
v.style = `
transform: translateX(${x > 0 ? 0 : x}px);
`
}
}
}
v.ontouchend = function (e) {
let endX = e.changedTouches[0].clientX
if (determineDirection(endX, startX)) {
if ((startX - endX) < 55) {
v.style = `
transform: translateX(0px);
`;
v.open = false
} else {
v.style = `
transform: translateX(-165px);
`
}
} else {
if ((endX - startX) < 55 && endX != startX) {
v.style = `
transform: translateX(-165px);
`
} else {
v.style = `
transform: translateX(0px);
`
v.open = false
}
}
}
})
// x1 moveX x2 startX true 左滑 false 右滑
function determineDirection(x1, x2) {
return x1 < x2 ? true : false
}
function $(className) {
return document.querySelector(className);
}
function _(className) {
return document.querySelectorAll(className);
}
</script>
</html>

View File

@@ -0,0 +1,75 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
margin: 0;
padding: 0;
width: 100%;
height: 100vh;
}
span {
position: fixed;
user-select: none;
transition: all 1s;
}
</style>
</head>
<body>
</body>
<script>
let text = ['富强','民主','文明','和谐','自由','平等','公正','法治','爱国','敬业','诚信','友善'],
index = 0;
$("body").onclick = function(e) {
// let x = e.x, y = e.y;
let { x,y } = e;
let span = document.createElement("span");
span.innerText = text[index]
span.style = `
left: ${x}px;
top: ${y}px;
color: hsl(${Math.random() * 360}, 100%, 50%);
`;
// span.style.position = `fixed`;
// span.style.left = `${x}px`;
// span.style.top = `${y}px`;
$("body").appendChild(span);
motion(span ,y)
index+=1;
if (index > 11) {
index = 0
}
}
function motion(el, top) {
setTimeout(function() {
el.style.top = `${top - 200}px`;
}, 300)
setTimeout(function() {
$("body").removeChild(el);
}, 1300)
}
function $(className) {
return document.querySelector(className);
}
function _(className) {
return document.querySelectorAll(className);
}
</script>
</html>

View File

@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>搜索建议</title>
<style>
span {
color: red;
font-weight: 700;
}
</style>
</head>
<body>
<input type="text" placeholder="输入关键字">
<ul>
</ul>
</body>
<script>
var SearchList = [
'你好', '我不好', '今天天气不好', '明天吃什么', '你说什么', '你不想学习?'
];
var newList = []
$("input").oninput = function () {
newList = []
if ($("input").value.length != 0) {
SearchList.forEach(function (v) {
if (v.includes($("input").value)) {
let newText = v.replaceAll($("input").value, `<span>${$("input").value}</span>`)
newList.push(newText)
}
})
renderList()
} else {
$("ul").innerHTML = ""
}
}
function renderList() {
$("ul").innerHTML = ""
newList.forEach(function (item) {
$("ul").innerHTML += `<li>${item}</li>`
})
}
function $(className) {
return document.querySelector(className);
}
function _(className) {
return document.querySelectorAll(className);
}
</script>
</html>

View File

@@ -0,0 +1,12 @@
body,ul,p,h1,h2,h3,h4,h5,h6 {
margin: 0;
padding: 0;
}
html {
/* font-size: 50px; */
}
body {
font-size: 0;
}

View File

@@ -0,0 +1,148 @@
body {
height: 100vh;
background: url("../img/back.png");
background-size: contain;
user-select: none;
}
.diban {
position: fixed;
width: 100%;
height: 112px;
left: 0;
bottom: 0;
background: red;
}
.diban img {
position: absolute;
width: 100%;
height: 100%;
}
.bird {
position: fixed;
left: 100px;
width: 34px;
height: 24px;
transition: all linear 0.15s;
z-index: 999;
}
.pipe {
position: fixed;
width: 55px;
z-index: 998;
transition: all linear 0.1s;
}
.pause {
position: fixed;
top: 30px;
left: 30px;
cursor: pointer;
z-index: 999;
}
.score {
position: fixed;
top: 30px;
left: 50%;
transform: translateX(-50%);
z-index: 999;
}
.up {
transform: rotate(-38deg);
}
.down {
transform: rotate(90deg);
}
/* .birdDefault {
animation: birdDefault 0.4s linear infinite reverse;
}
.birdBlue {
animation: birdBlue 0.4s linear infinite reverse;
}
.birdRed {
animation: birdRed 0.4s linear infinite reverse;
} */
@keyframes birdShake {
0% {
transform: translateY(0px);
}
33% {
transform: translateY(15px);
}
100% {
transform: translateY(0px);
}
}
@keyframes birdDefault {
0% {
background: url("../img/hn1.png");
}
33% {
background: url("../img/hn2.png");
}
100% {
background: url("../img/hn3.png");
}
}
@keyframes birdBlue {
0% {
background: url("../img/hn_blue_1.png");
}
33% {
background: url("../img/hn_blue_2.png");
}
100% {
background: url("../img/hn_blue_3.png");
}
}
@keyframes birdRed {
0% {
background: url("../img/hn_red_1.png");
}
33% {
background: url("../img/hn_red_2.png");
}
100% {
background: url("../img/hn_red_3.png");
}
}
.bird_title {
position: absolute;
left: 50%;
top: 40%;
transform: translate(-50%, -40%);
text-align: center;
z-index: 999;
}
.bird_list {
display: flex;
align-items: center;
justify-content: space-between;
}
.bird_list img {
cursor: pointer;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>水管鸟</title>
<link rel="stylesheet" href="./css/clear.css">
<link rel="stylesheet" href="./css/index.css">
</head>
<body>
<div class="bird" style="animation: birdDefault 0.4s linear infinite reverse, birdShake 0.4s linear infinite reverse;"></div>
<img style="display: none;" class="pause" src="./img/pause.png" alt="">
<div class="score" style="display: none;">
<img src="./img/0.png" alt="">
</div>
<div class="bird_title">
<img class="bird_logo" src="./img/title.png" alt="">
<div class="bird_list">
<img src="./img/hn1.png" alt="">
<img src="./img/hn_blue_1.png" alt="">
<img src="./img/hn_red_1.png" alt="">
</div>
<div></div>
<img class="start" src="./img/start.png" alt="">
<img style="display: none;" class="gameover" src="./img/gameover.png" alt="">
<img style="display: none;" class="restart" src="./img/start.png" alt="">
<img style="display: none;" class="reload" src="./img/start.png" alt="">
</div>
<div class="diban">
<img class="di_one" src="./img/diban.png" alt="">
<img class="di_two" src="./img/diban.png" alt="">
</div>
</body>
<script src="./js/utils.js"></script>
<script src="./js/index.js"></script>
</html>

View File

@@ -0,0 +1,265 @@
class WaterPipeBird {
innerWidth = window.innerWidth;
innerHeight = window.innerHeight;
totalScore = 0;
// 地板的运动速度
dibanMotionSpeed = 10;
// 鸟的默认皮肤
birdTheme = "birdDefault"
// 游戏状态 true 开始, false 未开始
gameStatus = false;
// 每次点击鸟,鸟的上移动距离
birdClickTop = 40
// 下移距离
birdClickDown = 10
// 创建到第几个水管
PipeIndex = 0;
// 上下水管的通过间隙(距离)
PipeGap = 150;
// 水管左右的间距
XPipeWidth = 300
// 水管移动速度
PipeSpeed = 10
IntervalList = []
constructor() {
console.log("构造函数: ");
this.dibanMotion()
this.initBird()
this.startGame()
this.stopGame()
}
dibanMotion() {
$(".di_one").style.left = `0px`;
$(".di_two").style.left = `${this.innerWidth}px`;
// 定义变量提前保存this
// =>
// call bind apply
// 箭头函数因为没有关键词 function所以this会被解绑
setInterval(() => {
$(".di_one").style.left = `${parseInt(($(".di_one").style.left)) - this.dibanMotionSpeed}px`;
$(".di_two").style.left = `${parseInt(($(".di_two").style.left)) - this.dibanMotionSpeed}px`;
if (parseInt(($(".di_one").style.left)) <= -this.innerWidth) {
$(".di_one").style.left = `${this.innerWidth}px`;
}
if (parseInt(($(".di_two").style.left)) <= -this.innerWidth) {
$(".di_two").style.left = `${this.innerWidth}px`;
}
}, 100)
}
// birdShake 0.4s linear infinite reverse
initBird() {
$(".bird").style.top = `${(this.innerHeight - 112) / 2 - 14}px`;
// 点击切换小鸟的主题
_(".bird_list img").forEach((v, i) => {
v.onclick = () => {
switch (i) {
case 0:
this.birdTheme = "birdDefault"
$(".bird").style.animationName = "birdDefault,birdShake"
break;
case 1:
this.birdTheme = "birdBlue"
$(".bird").style.animationName = "birdBlue,birdShake"
break;
case 2:
this.birdTheme = "birdRed"
$(".bird").style.animationName = "birdRed,birdShake"
break;
default:
break;
}
}
})
}
startGame() {
e(".start", () => {
let clickTime = null;
this.gameStatus = true;
$(".pause").show();
$(".score").show();
$(".bird_title").none();
$(".bird").style.animationName = this.birdTheme
// 下落
this.IntervalList[0] = setInterval(() => {
if (this.gameStatus) {
$(".bird").style.top = `${parseInt($(".bird").style.top) + this.birdClickDown}px`
this.collision($(".bird"), $(".diban"))
}
}, 1000 / 16)
// 点击开始游戏和控制鸟的上移
e("body", (e) => {
if (this.gameStatus) {
clickTime = new Date().getTime();
$(".bird").style.top = `${parseInt($(".bird").style.top) - this.birdClickTop}px`
$(".bird").remove("down")
$(".bird").add("up")
}
})
// 下落的样式
this.IntervalList[1] = setInterval(() => {
let currentTime = new Date().getTime();
if (currentTime - clickTime > 300) {
$(".bird").remove("up")
$(".bird").add("down")
}
}, 300)
this.IntervalList[2] = setInterval(() => {
this.CreatedPipe()
}, 500)
})
}
stopGame() {
e(".pause", (e) => {
this.gameStatus = false;
e?.stopPropagation();
this.IntervalList.forEach(v => {
clearInterval(v)
})
_(".pipe").forEach(v => {
clearInterval(v.IntervalId)
})
$(".bird_list").none()
$(".start").none()
$(".bird_title").show()
$(".restart").show()
})
e(".restart", (e) => {
$(".start").onclick()
this.PipeMove(_(".pipe"))
})
}
CreatedPipe() {
let PipeTotalHeight = this.innerHeight - 112 - this.PipeGap;
let TopImgHeight = getRandom(60, PipeTotalHeight - 60)
let BottomImgHeight = PipeTotalHeight - TopImgHeight
let createdImg = (t) => {
let img = document.createElement("img")
img.type = t
img.src = `./img/sg_${t}.png`
img.className = "pipe"
img.style = `
${t == "b" ? 'bottom: 110px;' : 'top: 0px;'}
left: ${this.innerWidth + 55 + (this.PipeIndex * this.XPipeWidth)}px;
height: ${t == "t" ? TopImgHeight : BottomImgHeight}px;
`;
return img
}
let topImg = createdImg("t");
let bottomImg = createdImg("b");
$("body").appendChild(topImg)
$("body").appendChild(bottomImg)
this.PipeMove([topImg, bottomImg])
// this.PipeMove(bottomImg)
this.PipeIndex += 1
}
PipeMove(arr) {
arr.forEach(img => {
img.IntervalId = setInterval(() => {
if (this.gameStatus) {
img.style.left = `${parseInt(img.style.left) - this.PipeSpeed}px`
if (parseInt(img.style.left) <= -55) {
clearInterval(img.IntervalId)
$("body").removeChild(img)
} else {
this.collision($(".bird"), img)
}
}
}, 100)
})
}
collision(el1, el2) {
if (el1.offsetLeft < el2.offsetLeft + el2.offsetWidth &&
el1.offsetLeft + el1.offsetWidth > el2.offsetLeft &&
el1.offsetTop < el2.offsetTop + el2.offsetHeight &&
el1.offsetHeight + el1.offsetTop > el2.offsetTop
) {
$(".gameover").show()
$(".bird_logo").none();
$(".pause").onclick()
$(".restart").none();
$(".reload").show()
e(".reload", () => {
location.reload()
})
} else {
if (el2.type == "t") {
if (parseInt(el2.style.left) + el2.offsetWidth == 100) {
this.totalScore += 1
let sco = this.totalScore.toString().split("")
$(".score").innerHTML = ""
sco.forEach(v => {
$(".score").innerHTML += `<img src="./img/${v}.png" alt="">`
})
}
}
}
}
}
// var a = function (test) {
// console.log("1: ", test);
// }
// var a = test => console.log("1: ", test);
new WaterPipeBird()

View File

@@ -0,0 +1,57 @@
class Utils {
$(className) {
return document.querySelector(className);
}
_(className) {
return document.querySelectorAll(className);
}
e(className, callback, type = "click",) {
$(`${className}`)[`on${type}`] = (event) => {
callback(event)
}
}
customMethods() {
Element.prototype.add = function(className) {
this.classList.add(className)
}
Element.prototype.remove = function(className) {
this.classList.remove(className)
}
Element.prototype.none = function() {
this.style.display = "none"
}
Element.prototype.show = function() {
this.style.display = "block"
}
Element.prototype.toggle = function() {
if (this.style.display == "none") {
this.style.display = "block"
} else {
this.style.display = "none"
}
}
}
getRandom(min, max) {
const floatRandom = Math.random()
const difference = max - min
const random = Math.round(difference * floatRandom)
const randomWithinRange = random + min
return randomWithinRange
}
}
let { $, _, e, customMethods, getRandom } = new Utils()
customMethods()
// let utils = new Utils()

View File

@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="main">
<div class="test">
<button>点我</button>
</div>
</div>
</body>
<script src="./js/utils.js"></script>
<script src="./js/index.js"></script>
<script>
e(".main", () => {
alert(2)
})
e(".test", (e) => {
e.stopPropagation();
alert(3)
})
e("button", (e) => {
alert(1)
})
</script>
</html>

View File

@@ -0,0 +1,175 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
margin: 0;
padding: 0;
}
img {
height: 85px;
width: 70px;
position: fixed;
}
.dialog {
position: fixed;
width: 100%;
height: 100%;
background: #000000ba;
z-index: 999;
}
.dialog .center {
width: 400px;
height: 300px;
background: #fff;
border-radius: 10px;
box-sizing: border-box;
padding: 10px;
display: flex;
flex-direction: column;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.dialog .center .dialog_title {
display: flex;
align-items: center;
justify-content: space-between;
height: 40px;
border-bottom: 1px solid #e0e0e0;
}
.dialog_title .close {
font-size: 30px;
cursor: pointer;
}
.dialog .center .dialog_content {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
}
</style>
</head>
<body>
<div style="display: none;" class="dialog">
<div class="center">
<div class="dialog_title">
<div class="text">恭喜中奖</div>
<div class="close">x</div>
</div>
<div class="dialog_content">
恭喜中的三等奖
</div>
</div>
</div>
</body>
<script>
let { innerWidth, innerHeight } = window, createdId = null, gImg = null;
// 生成随机x轴红包
function createdHb() {
let img = document.createElement("img");
let left = Math.random() * (innerWidth - 70);
img.src = "./hb.png";
img.style = `
left: ${left}px;
top: -85px;
`
img.onclick = function () {
gImg = img;
clearInterval(createdId)
_("img").forEach(function (img) {
clearInterval(img.IntervalId)
})
random()
$(".dialog").style.display = "block"
}
$("body").appendChild(img);
motion(img)
}
function motion(img) {
img.IntervalId = setInterval(function () {
let newTop = parseInt(img.style.top);
if (newTop >= innerHeight) {
$("body").removeChild(img);
clearInterval(img.IntervalId)
} else {
img.style.top = `${newTop + 10}px`;
}
}, 80)
}
$(".dialog_title .close").onclick = function () {
$(".dialog").style.display = "none"
$("body").removeChild(gImg);
clearInterval(gImg.IntervalId)
_("img").forEach(function (img) {
motion(img)
})
auto()
}
function random() {
let leavel = Math.random()
console.log(leavel);
if (leavel < 0.01) {
$(".dialog_content").innerText = "一等奖"
} else if (0.01< leavel && leavel <= 0.1) {
$(".dialog_content").innerText = "二等奖"
} else {
$(".dialog_content").innerText = "三等奖"
}
}
// createdHb()
function auto() {
createdId = setInterval(function () {
createdHb()
}, 300)
}
auto()
// 让红包运动
// 拆红包的所有功能
// 让被点击的红包停止运动,生成新红包的也停止运动,已有红包也要停止运动
// 一等奖(1) 二等奖(10) 三等奖(89)
function $(className) {
return document.querySelector(className);
}
function _(className) {
return document.querySelectorAll(className);
}
</script>
</html>

View File

@@ -0,0 +1,6 @@
@import "../public/_.css";
h1 {
color: var(--themeColor);
font-size: var(--f24);
}

View File

@@ -0,0 +1,4 @@
@import "./color.css";
@import "./size.css";
@import "./utils.css";
@import "./normalize.css";

View File

@@ -0,0 +1,3 @@
:root {
--themeColor:red;
}

View File

@@ -0,0 +1,356 @@
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
/* Document
========================================================================== */
/**
* 1. Correct the line height in all browsers.
* 2. Prevent adjustments of font size after orientation changes in iOS.
*/
body {
font-size: 0;
}
html {
line-height: 1;
-webkit-text-size-adjust: 100%; /* 2 */
}
/* Sections
========================================================================== */
/**
* Remove the margin in all browsers.
*/
body,ul,li,p,h1,h2,h3,h4,h5,h6{
margin: 0;
padding: 0;
list-style: none;
}
/**
* Render the `main` element consistently in IE.
*/
main {
display: block;
}
/**
* Correct the font size and margin on `h1` elements within `section` and
* `article` contexts in Chrome, Firefox, and Safari.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/* Grouping content
========================================================================== */
/**
* 1. Add the correct box sizing in Firefox.
* 2. Show the overflow in Edge and IE.
*/
hr {
box-sizing: content-box; /* 1 */
height: 0; /* 1 */
overflow: visible; /* 2 */
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
pre {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/* Text-level semantics
========================================================================== */
/**
* Remove the gray background on active links in IE 10.
*/
a {
background-color: transparent;
text-decoration: none;
}
/**
* 1. Remove the bottom border in Chrome 57-
* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
*/
abbr[title] {
border-bottom: none; /* 1 */
text-decoration: underline; /* 2 */
text-decoration: underline dotted; /* 2 */
}
/**
* Add the correct font weight in Chrome, Edge, and Safari.
*/
b,
strong {
font-weight: bolder;
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
code,
kbd,
samp {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/**
* Add the correct font size in all browsers.
*/
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` elements from affecting the line height in
* all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
/* Embedded content
========================================================================== */
/**
* Remove the border on images inside links in IE 10.
*/
img {
border-style: none;
}
/* Forms
========================================================================== */
/**
* 1. Change the font styles in all browsers.
* 2. Remove the margin in Firefox and Safari.
*/
button,
input,
optgroup,
select,
textarea {
font-family: inherit; /* 1 */
font-size: 100%; /* 1 */
line-height: 1.15; /* 1 */
margin: 0; /* 2 */
}
/**
* Show the overflow in IE.
* 1. Show the overflow in Edge.
*/
button,
input { /* 1 */
overflow: visible;
}
/**
* Remove the inheritance of text transform in Edge, Firefox, and IE.
* 1. Remove the inheritance of text transform in Firefox.
*/
button,
select { /* 1 */
text-transform: none;
}
/**
* Correct the inability to style clickable types in iOS and Safari.
*/
button,
[type="button"],
[type="reset"],
[type="submit"] {
-webkit-appearance: button;
}
/**
* Remove the inner border and padding in Firefox.
*/
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
border-style: none;
padding: 0;
}
/**
* Restore the focus styles unset by the previous rule.
*/
button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {
outline: 1px dotted ButtonText;
}
/**
* Correct the padding in Firefox.
*/
fieldset {
padding: 0.35em 0.75em 0.625em;
}
/**
* 1. Correct the text wrapping in Edge and IE.
* 2. Correct the color inheritance from `fieldset` elements in IE.
* 3. Remove the padding so developers are not caught out when they zero out
* `fieldset` elements in all browsers.
*/
legend {
box-sizing: border-box; /* 1 */
color: inherit; /* 2 */
display: table; /* 1 */
max-width: 100%; /* 1 */
padding: 0; /* 3 */
white-space: normal; /* 1 */
}
/**
* Add the correct vertical alignment in Chrome, Firefox, and Opera.
*/
progress {
vertical-align: baseline;
}
/**
* Remove the default vertical scrollbar in IE 10+.
*/
textarea {
overflow: auto;
}
/**
* 1. Add the correct box sizing in IE 10.
* 2. Remove the padding in IE 10.
*/
[type="checkbox"],
[type="radio"] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/**
* Correct the cursor style of increment and decrement buttons in Chrome.
*/
[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
height: auto;
}
/**
* 1. Correct the odd appearance in Chrome and Safari.
* 2. Correct the outline style in Safari.
*/
[type="search"] {
-webkit-appearance: textfield; /* 1 */
outline-offset: -2px; /* 2 */
}
/**
* Remove the inner padding in Chrome and Safari on macOS.
*/
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
/**
* 1. Correct the inability to style clickable types in iOS and Safari.
* 2. Change font properties to `inherit` in Safari.
*/
::-webkit-file-upload-button {
-webkit-appearance: button; /* 1 */
font: inherit; /* 2 */
}
/* Interactive
========================================================================== */
/*
* Add the correct display in Edge, IE 10+, and Firefox.
*/
details {
display: block;
}
/*
* Add the correct display in all browsers.
*/
summary {
display: list-item;
}
/* Misc
========================================================================== */
/**
* Add the correct display in IE 10+.
*/
template {
display: none;
}
/**
* Add the correct display in IE 10.
*/
[hidden] {
display: none;
}

View File

@@ -0,0 +1,15 @@
:root {
--f12: 12px;
--f13: 13px;
--f14: 14px;
--f15: 15px;
--f16: 16px;
--f17: 17px;
--f18: 18px;
--f19: 19px;
--f20: 20px;
--f21: 21px;
--f22: 22px;
--f23: 23px;
--f24: 24px;
}

View File

@@ -0,0 +1,3 @@
.clear {
clear: both;
}

View File

@@ -0,0 +1,37 @@
// 放程序配置的,比如接口地址
var config = {
devBaseUrl: 'http://127.0.0.1:3000/api/json',
testBaseUrl: 'http://127.0.0.1:3000/api/json/test',
prodBaseUrl: 'http://www.abc.com/api/json',
stage: 'dev', // dev test prod
urlList: {
classList: '/classList',
info: '/info',
},
getBaseUrl: function () {
switch (this.stage) {
case "dev":
return this.devBaseUrl;
break;
case "test":
return this.testBaseUrl;
break;
case "prod":
return this.prodBaseUrl;
break;
default:
break;
}
}
}
// 基地址
// 三个
// dev 开发阶段 http://127.0.0.1:3000/api/json/dev
// test 测试阶段 http://127.0.0.1:3000/api/json/test
// prod 上线阶段 http://www.abc.com/api/json
// http://127.0.0.1:3000/api/json /classList
// http://127.0.0.1:3000/api/json /info

View File

@@ -0,0 +1,78 @@
class Http {
defaultOption = {
timeout: 6000,
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
}
constructor() {
this.xhr = new XMLHttpRequest()
}
get(par) {
return new Promise((success, error) => {
this.setOption(par)
let urlParams = ""
for (const key in par.data) {
urlParams += `&${key}=${par.data[key]}`
}
urlParams = urlParams.replace("&", "")
this.xhr.open("GET", `${config.getBaseUrl()}${par.url}?${urlParams}`)
this.xhr.timeout = this.defaultOption.timeout
this.setHeader(par.headers)
this.xhr.send()
this.statechange(success, error);
})
}
post(par) {
return new Promise((success, error) => {
this.setOption(par)
this.xhr.open("POST", par.url)
this.xhr.timeout = this.defaultOption.timeout
this.setHeader(par.headers)
this.xhr.send(JSON.stringify(par.data))
this.statechange(success, error);
})
}
setOption(par) {
this.defaultOption.timeout = par.timeout || this.defaultOption.timeout
// ....
}
setHeader(headerObject = {}) {
Object.assign(headerObject, this.defaultOption.headers)
for (const key in headerObject) {
this.xhr.setRequestHeader(key, headerObject[key]);
}
}
statechange(success, error) {
this.xhr.onreadystatechange = () => {
if (this.xhr.readyState == 4) {
if (this.xhr.status == 200) {
let data = JSON.parse(this.xhr.response)
switch (data.status) {
case 200:
success(data.result)
break;
case 404:
alert(data.msg)
console.error(this.xhr);
throw new Error(data.msg)
break;
default:
break;
}
} else {
error(this.xhr)
}
}
}
}
}
var http = new Http();

View File

@@ -0,0 +1,16 @@
class Index {
constructor() {
// console.log(config.getBaseUrl());
this.getClassList()
}
async getClassList() {
let res = await indexServe.classList({
id: 253,
page: 1
});
console.log(res);
}
}
new Index()

View File

@@ -0,0 +1,17 @@
class IndexServe {
async classList(data = {}, headers = {}) {
return await http.get({
url: config.urlList.classList,
data,
headers
});
}
async activity() {
}
}
var indexServe = new IndexServe()

View File

@@ -0,0 +1,56 @@
class Utils {
$(className) {
return document.querySelector(className);
}
_(className) {
return document.querySelectorAll(className);
}
click(className, callback, type = "click",) {
$(`${className}`)[`on${type}`] = (event) => {
callback(event)
}
}
query(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null)
return unescape(r[2]);
return null;
}
customMethods() {
Element.prototype.add = function(className) {
this.classList.add(className)
}
Element.prototype.remove = function(className) {
this.classList.remove(className)
}
Element.prototype.none = function() {
this.style.display = "none"
}
Element.prototype.show = function() {
this.style.display = "block"
}
Element.prototype.toggle = function() {
if (this.style.display == "none") {
this.style.display = "block"
} else {
this.style.display = "none"
}
}
}
}
let { $, _, click, customMethods, query } = new Utils()
customMethods()

View File

@@ -0,0 +1,10 @@
((w, d) => {
function setSize() {
var screenWidth = d.documentElement.clientWidth;
var currentFontSize = screenWidth * 100 / 750;
d.documentElement.style.fontSize = currentFontSize + 'px';
}
w.addEventListener('resize', setSize);
w.addEventListener('pageShow', setSize)
w.addEventListener('DOMContentLoaded', setSize)
})(window, document)

View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../js/utils/rem.js"></script>
<link rel="stylesheet" href="../css/page/index.css">
</head>
<body>
<h1 class="clear">哈哈</h1>
</body>
<script src="../js/config/index.js"></script>
<script src="../js/utils/index.js"></script>
<script src="../js/http/index.js"></script>
<script src="../js/serve/index.js"></script>
<script src="../js/page/index.js"></script>
</html>

View File

@@ -0,0 +1,31 @@
/*
* Eslint config file
* Documentation: https://eslint.org/docs/user-guide/configuring/
* Install the Eslint extension before using this feature.
*/
module.exports = {
env: {
es6: true,
browser: true,
node: true,
},
ecmaFeatures: {
modules: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
globals: {
wx: true,
App: true,
Page: true,
getCurrentPages: true,
getApp: true,
Component: true,
requirePlugin: true,
requireMiniProgram: true,
},
// extends: 'eslint:recommended',
rules: {},
}

View File

@@ -0,0 +1,58 @@
import config from "../config/index";
class Api {
async getRequest(params) {
wx.showLoading({
title: '加载中..'
});
return new Promise((resolve, reject) => {
wx.request({
method: 'GET',
url: config.checkBaseUrl() + params.url,
data: params.data,
header: Object.assign({
token: wx.getStorageSync('token')
}, params.header),
success: (res) => {
this.inter(resolve, reject, res.data)
}
});
})
}
async postRequest(params) {
return new Promise((resolve, reject) => {
wx.request({
method: 'POST',
url: config.checkBaseUrl() + params.url,
data: params.data,
header: Object.assign({
token: wx.getStorageSync('token')
}, params.header),
success: (res) => {
this.inter(resolve, reject, res.data)
}
});
})
}
inter(resolve, reject, data) {
wx.hideLoading();
switch (data.status) {
case 200:
resolve(data.result)
break;
case 404:
Toast.fail(data.msg);
throw new Error(data.msg);
break;
default:
break;
}
}
}
export default new Api()

View File

@@ -0,0 +1,6 @@
import serve from "./serve/_"
App({
globalData: {
...serve
}
})

View File

@@ -0,0 +1,27 @@
{
"pages": [
"pages/index/index",
"pages/about/about",
"pages/info/info"
],
"subpackages": [
{
"root": "integral",
"pages": [
"pages/home/home"
]
}
],
"window": {
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "",
"backgroundColor": "#eeeeee",
"backgroundTextStyle": "light"
},
"sitemapLocation": "sitemap.json",
"usingComponents": {
"header": "/components/header/header",
"van-button": "@vant/weapp/button/index"
}
}

View File

@@ -0,0 +1,40 @@
// components/header/header.js
Component({
options: {
multipleSlots: true
},
/**
* 组件的属性列表
*/
properties: {
title: {
type: String,
value: "默认数值"
}
},
/**
* 组件的初始数据
*/
data: {
test: '测试数据,哈哈哈哈'
},
observers: {
'test': function (newTest) {
console.log("newTest: ", newTest);
}
},
/**
* 组件的方法列表
*/
methods: {
test() {
this.setData({
test: "你好"
})
this.triggerEvent("change", this.data.test)
}
}
})

View File

@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}

View File

@@ -0,0 +1,12 @@
<view class="header">
<view bind:tap="test">
头部组件 {{ title }}
<view class="left">
<slot name="left"></slot>
</view>
<view class="right">
<slot name="right"></slot>
</view>
</view>
</view>

View File

@@ -0,0 +1 @@
/* components/header/header.wxss */

View File

@@ -0,0 +1,21 @@
export default {
devBaseUrl: 'http://127.0.0.1:3000/api/json',
prodBaseUrl: 'http://127.0.0.1:3000/api/json',
apiList: {
index: '/index'
},
checkBaseUrl() {
switch (__wxConfig.envVersion) {
case "develop":
return this.devBaseUrl
break;
case "release":
return this.prodBaseUrl
break;
default:
break;
}
}
}

View File

@@ -0,0 +1,66 @@
// integral/pages/home/home.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

View File

@@ -0,0 +1,3 @@
{
"usingComponents": {}
}

View File

@@ -0,0 +1,2 @@
<!--integral/pages/home/home.wxml-->
<text>integral/pages/home/home.wxml</text>

View File

@@ -0,0 +1 @@
/* integral/pages/home/home.wxss */

View File

@@ -0,0 +1,21 @@
{
"name": "minstudy",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "minstudy",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"@vant/weapp": "^1.10.23"
}
},
"node_modules/@vant/weapp": {
"version": "1.10.23",
"resolved": "https://registry.npmmirror.com/@vant/weapp/-/weapp-1.10.23.tgz",
"integrity": "sha512-Lqlc0oT89AxR8e4uLmP59xkI1KkWSTWKWV9kXM17CJz55eL0fPMo5jd0d132KpcfRmiwIOVr7TwK8u8v6XIhlg=="
}
}
}

View File

@@ -0,0 +1,15 @@
{
"name": "minstudy",
"version": "1.0.0",
"description": "",
"main": ".eslintrc.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@vant/weapp": "^1.10.23"
}
}

View File

@@ -0,0 +1,66 @@
// pages/about/about.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

View File

@@ -0,0 +1,3 @@
{
"usingComponents": {}
}

View File

@@ -0,0 +1,3 @@
<view class="about">
<text>我的页面</text>
</view>

View File

@@ -0,0 +1 @@
/* pages/about/about.wxss */

Some files were not shown because too many files have changed in this diff Show More