fix: 修改多端模板

This commit is contained in:
NICE CODE BY DEV 2022-05-26 17:47:50 +08:00
parent e3ce650ef8
commit 01c3f9e0d0
51 changed files with 238 additions and 13870 deletions

View File

@ -7,10 +7,6 @@ indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
quote_type = single
[*.js, *.jsx, *.ts, *.tsx]
quote_type = single
[*.md]
trim_trailing_whitespace = false

7
.eslintrc Normal file
View File

@ -0,0 +1,7 @@
{
"extends": ["taro/react"],
"rules": {
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off"
}
}

View File

@ -1,4 +0,0 @@
module.exports = {
extends: [],
rules: {},
};

View File

@ -1,14 +1,11 @@
// babel-preset-taro 更多选项和默认值:
// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
module.exports = {
sourceMap: false,
presets: [
[
'taro',
{
framework: 'react',
ts: true,
},
],
],
};
['taro', {
framework: 'react',
ts: true,
'dynamic-import-node': true
}]
]
}

View File

@ -1,10 +1,9 @@
module.exports = {
env: {
NODE_ENV: '"test"',
BASE_URL: '""', // 小程序使用,直接请求
BASE_API: '"/api"', // h5使用代理请求
NODE_ENV: '"development"'
},
defineConstants: {
},
defineConstants: {},
mini: {},
h5: {},
};
h5: {}
}

View File

@ -1,46 +1,51 @@
const path = require('path');
const config = {
projectName: 'taro-template',
date: '2020-9-23',
projectName: 'a',
date: '2022-5-26',
designWidth: 750,
deviceRatio: {
640: 2.34 / 2,
750: 1,
828: 1.81 / 2,
828: 1.81 / 2
},
sourceRoot: 'src',
outputRoot: 'dist',
plugins: [],
defineConstants: {},
defineConstants: {
},
copy: {
patterns: [],
options: {},
patterns: [
],
options: {
}
},
framework: 'react',
alias: {
'@': path.resolve(__dirname, '..', 'src'),
},
mini: {
postcss: {
pxtransform: {
enable: true,
config: {},
config: {
}
},
url: {
enable: true,
config: {
limit: 1024, // 设定转换尺寸上限
},
limit: 1024 // 设定转换尺寸上限
}
},
cssModules: {
enable: true, // 默认为 false如需使用 css modules 功能,则设为 true
enable: false, // 默认为 false如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]',
},
},
},
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
}
},
copy: process.env.TARO_ENV !== 'h5' ? {} : {
patterns: [
{ from: "public", to: "dist" },
]
},
h5: {
publicPath: '/',
@ -48,39 +53,23 @@ const config = {
postcss: {
autoprefixer: {
enable: true,
config: {},
config: {
}
},
cssModules: {
enable: true, // 默认为 false如需使用 css modules 功能,则设为 true
enable: false, // 默认为 false如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]',
},
},
},
esnextModules: ['taro-ui'],
devServer: {
proxy: {
'/api': {
target: 'http://mock.uniubi.com',
pathRewrite: {
'^/api': '',
},
},
},
},
},
};
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
}
}
}
module.exports = function (merge) {
if (process.env.NODE_ENV === 'dev') {
return merge({}, config, require('./dev'));
} else if (process.env.NODE_ENV === 'test') {
return merge({}, config, require('./test'));
} else if (process.env.NODE_ENV === 'release') {
return merge({}, config, require('./release'));
} else if (process.env.NODE_ENV === 'pre') {
return merge({}, config, require('./pre'));
if (process.env.NODE_ENV === 'development') {
return merge({}, config, require('./dev'))
}
return merge({}, config, require('./prod'));
};
return merge({}, config, require('./prod'))
}

View File

@ -1,10 +0,0 @@
module.exports = {
env: {
NODE_ENV: '"pre"',
BASE_URL: '""', // 小程序使用,直接请求
BASE_API: '"/api"', // h5使用代理请求
},
defineConstants: {},
mini: {},
h5: {},
};

View File

@ -1,19 +1,37 @@
module.exports = {
env: {
NODE_ENV: '"production"',
BASE_URL: '""', // 小程序使用,直接请求
BASE_API: '"/api"', // h5使用代理请求
NODE_ENV: '"production"'
},
defineConstants: {
},
defineConstants: {},
mini: {},
h5: {
/**
* 如果h5端编译后体积过大可以使用webpack-bundle-analyzer插件对打包体积进行分析
* 参考代码如下
* webpackChain (chain) {
* chain.plugin('analyzer')
* .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])
* }
* WebpackChain 插件配置
* @docs https://github.com/neutrinojs/webpack-chain
*/
},
};
// webpackChain (chain) {
// /**
// * 如果 h5 端编译后体积过大,可以使用 webpack-bundle-analyzer 插件对打包体积进行分析。
// * @docs https://github.com/webpack-contrib/webpack-bundle-analyzer
// */
// chain.plugin('analyzer')
// .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])
// /**
// * 如果 h5 端首屏加载时间过长,可以使用 prerender-spa-plugin 插件预加载首页。
// * @docs https://github.com/chrisvfritz/prerender-spa-plugin
// */
// const path = require('path')
// const Prerender = require('prerender-spa-plugin')
// const staticDir = path.join(__dirname, '..', 'dist')
// chain
// .plugin('prerender')
// .use(new Prerender({
// staticDir,
// routes: [ '/pages/index/index' ],
// postProcess: (context) => ({ ...context, outputPath: path.join(staticDir, 'index.html') })
// }))
// }
}
}

View File

@ -1,10 +0,0 @@
module.exports = {
env: {
NODE_ENV: '"release"',
BASE_URL: '""', // 小程序使用,直接请求
BASE_API: '"/api"', // h5使用代理请求
},
defineConstants: {},
mini: {},
h5: {},
};

View File

@ -1,10 +0,0 @@
module.exports = {
env: {
NODE_ENV: '"test"',
BASE_URL: '""', // 小程序使用,直接请求
BASE_API: '"/api"', // h5使用代理请求
},
defineConstants: {},
mini: {},
h5: {},
};

23
global.d.ts vendored
View File

@ -1,3 +1,5 @@
/// <reference types="@tarojs/taro" />
declare module '*.png';
declare module '*.gif';
declare module '*.jpg';
@ -9,19 +11,8 @@ declare module '*.scss';
declare module '*.sass';
declare module '*.styl';
// @ts-ignore
declare const process: {
env: {
TARO_ENV:
| 'weapp'
| 'swan'
| 'alipay'
| 'h5'
| 'rn'
| 'tt'
| 'quickapp'
| 'qq'
| 'jd';
[key: string]: any;
};
};
declare namespace NodeJS {
interface ProcessEnv {
TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd'
}
}

View File

@ -1,12 +1,12 @@
{
"name": "taro-template",
"name": "nicecode-taro-template",
"version": "1.0.0",
"private": true,
"description": "Taro 项目模版",
"description": "nicecode taro 模板",
"templateInfo": {
"name": "default",
"name": "pwa",
"typescript": true,
"css": "sass"
"css": "stylus"
},
"scripts": {
"build:weapp": "taro build --type weapp",
@ -26,78 +26,40 @@
"dev:rn": "npm run build:rn -- --watch",
"dev:qq": "npm run build:qq -- --watch",
"dev:jd": "npm run build:jd -- --watch",
"dev:quickapp": "npm run build:quickapp -- --watch",
"build:test": "cross-env NODE_ENV=test taro build --type h5",
"build:release": "cross-env NODE_ENV=release taro build --type h5",
"build:pre": "cross-env NODE_ENV=pre taro build --type h5",
"build:production": "cross-env NODE_ENV=production taro build --type h5",
"build:weapp:test": "cross-env NODE_ENV=test taro build --type weapp",
"build:weapp:release": "cross-env NODE_ENV=release taro build --type weapp",
"build:weapp:pre": "cross-env NODE_ENV=pre taro build --type weapp",
"build:weapp:production": "cross-env NODE_ENV=production taro build --type weapp",
"lint": "eslint 'src/**/*.{js,jsx,tsx,ts}'",
"lint:fix": "eslint 'src/**/*.{js,jsx,tsx,ts}' --fix",
"prettier": "prettier --write 'src/**/*.{less,scss,css,md,json}'"
"dev:quickapp": "npm run build:quickapp -- --watch"
},
"browserslist": [
"last 3 versions",
"Android >= 4.1",
"ios >= 8"
],
"author": "Json",
"author": "dev",
"dependencies": {
"@babel/runtime": "^7.7.7",
"@tarojs/components": "3.0.21",
"@tarojs/helper": "^3.0.21",
"@tarojs/react": "3.0.21",
"@tarojs/runtime": "3.0.21",
"@tarojs/taro": "3.0.21",
"classnames": "^2.2.6",
"react": "^16.10.0",
"react-dom": "^16.10.0",
"taro-ui": "3.0.0-alpha.3"
"@tarojs/components": "3.4.10",
"@tarojs/runtime": "3.4.10",
"@tarojs/taro": "3.4.10",
"@tarojs/plugin-framework-react": "3.4.10",
"@tarojs/react": "3.4.10",
"react-dom": "^17.0.0",
"react": "^17.0.0"
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/helper-compilation-targets": "^7.12.5",
"@babel/helper-create-class-features-plugin": "^7.12.1",
"@babel/plugin-syntax-async-generators": "^7.8.4",
"@babel/plugin-syntax-decorators": "^7.12.1",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-json-strings": "^7.8.3",
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3",
"@babel/plugin-syntax-numeric-separator": "^7.10.4",
"@babel/plugin-syntax-optional-catch-binding": "^7.8.3",
"@babel/plugin-transform-typescript": "^7.12.1",
"@babel/preset-env": "^7.12.11",
"@tarojs/mini-runner": "3.0.21",
"@tarojs/plugin-sass": "^2.2.10",
"@tarojs/webpack-runner": "3.0.21",
"@types/react": "^16.0.0",
"@types/webpack-env": "^1.13.6",
"babel-plugin-transform-jsx-stylesheet": "^1.0.0",
"babel-preset-taro": "3.0.21",
"cross-env": "^7.0.2",
"end-type-to-front-type": "^1.2.1",
"eslint": "^7.32.0",
"husky": "^7.0.2",
"lint-staged": "^11.1.2",
"prettier": "^2.3.2",
"@types/react": "^17.0.2",
"@tarojs/mini-runner": "3.4.10",
"@babel/core": "^7.8.0",
"@tarojs/webpack-runner": "3.4.10",
"babel-preset-taro": "3.4.10",
"eslint-config-taro": "3.4.10",
"eslint": "^8.12.0",
"eslint-plugin-react": "^7.8.2",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-react-hooks": "^4.2.0",
"offline-plugin": "^5.0.7",
"stylelint": "9.3.0",
"typescript": "^4.4.2",
"yorkie": "^2.0.0"
},
"gitHooks": {
"pre-commit": "lint-staged"
},
"lint-staged": {
"*.{js,jsx,tsx,ts}": [
"npm run lint:fix",
"git add ."
],
"*.{less,scss,css,md,json}": [
"npm run prettier",
"git add ."
]
"@typescript-eslint/parser": "^5.20.0",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"typescript": "^4.1.0"
}
}

View File

@ -1,7 +1,7 @@
{
"miniprogramRoot": "./dist",
"projectname": "taro-template",
"description": "Trao 项目模版",
"projectname": "a",
"description": "temp",
"appid": "touristappid",
"setting": {
"urlCheck": true,

9
project.tt.json Normal file
View File

@ -0,0 +1,9 @@
{
"miniprogramRoot": "./",
"projectname": "a",
"appid": "testAppId",
"setting": {
"es6": false,
"minified": false
}
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 473 B

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 20 KiB

BIN
public/icons/icon_x114.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
public/icons/icon_x144.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
public/icons/icon_x150.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
public/icons/icon_x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

BIN
public/icons/icon_x192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
public/icons/icon_x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

BIN
public/icons/icon_x512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
public/icons/icon_x57.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 697 B

BIN
public/icons/icon_x72.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

27
public/manifest.json Normal file
View File

@ -0,0 +1,27 @@
{
"short_name": "a",
"name": "a",
"description": "temp",
"scope": "/",
"start_url": "/?source=pwa",
"display": "standalone",
"background_color": "#0000C2",
"theme_color": "#0000C2",
"icons": [
{
"src": "/icons/icon_vector.svg",
"type": "image/svg+xml",
"sizes": "512x512"
},
{
"src": "/icons/icon_x192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/icons/icon_x512.png",
"type": "image/png",
"sizes": "512x512"
}
]
}

View File

@ -1,9 +1,11 @@
export default {
pages: ['pages/index/index'],
export default defineAppConfig({
pages: [
'pages/index/index'
],
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: 'WeChat',
navigationBarTextStyle: 'black',
},
};
navigationBarTextStyle: 'black'
}
})

0
src/app.styl Normal file
View File

View File

@ -1,13 +1,25 @@
import { Component } from 'react';
import './styles/custom-variables.scss';
import './styles/reset.scss';
import './styles/index.scss';
import { install } from 'offline-plugin/runtime'
import { Component } from 'react'
import './app.styl'
if (process.env.TARO_ENV === 'h5') {
install()
}
class App extends Component {
componentDidMount () {}
componentDidShow () {}
componentDidHide () {}
componentDidCatchError () {}
// this.props.children 是将要会渲染的页面
render() {
return this.props.children;
render () {
return this.props.children
}
}
export default App;
export default App

View File

@ -1 +0,0 @@
export const DEMO_MAP = new Map([[1, 'demo 1']]);

View File

@ -1,8 +0,0 @@
import React from 'react';
import { View } from '@tarojs/components';
const Demo: Taro.FC = () => {
return <View>demo</View>;
};
export default Demo;

View File

@ -2,13 +2,26 @@
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="width=device-width,initial-scale=1,user-scalable=no" name="viewport">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" >
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="format-detection" content="telephone=no,address=no">
<meta name="apple-mobile-web-app-title" content="a" />
<meta name="apple-mobile-web-app-status-bar-style" content="white">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
<title></title>
<meta name="application-name" content="a" />
<meta name="description" content="temp" />
<meta name="format-detection" content="telephone=no, address=no">
<meta name="theme-color" content="#0000C2" />
<meta name="msapplication-TileColor" content="#0000C2" />
<meta name="msapplication-TileImage" content="./icons/icon_x512.png" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" >
<link rel="icon" sizes="16x16" href="./icons/icon_x16.png" type="image/png" />
<link rel="icon" sizes="32x32" href="./icons/icon_x32.png" type="image/png" />
<link rel="apple-touch-icon" sizes="57x57" href="./icons/icon_x57.png" />
<link rel="apple-touch-icon" sizes="72x72" href="./icons/icon_x72.png" />
<link rel="apple-touch-icon" sizes="114x114" href="./icons/icon_x114.png" />
<link rel="apple-touch-icon" sizes="144x144" href="./icons/icon_x144.png" />
<link rel="manifest" href="./manifest.json" />
<title>a</title>
<script>
!function(x){function w(){var v,u,t,tes,s=x.document,r=s.documentElement,a=r.getBoundingClientRect().width;if(!v&&!u){var n=!!x.navigator.appVersion.match(/AppleWebKit.*Mobile.*/);v=x.devicePixelRatio;tes=x.devicePixelRatio;v=n?v:1,u=1/v}if(a>=640){r.style.fontSize="40px"}else{if(a<=320){r.style.fontSize="20px"}else{r.style.fontSize=a/320*20+"px"}}}x.addEventListener("resize",function(){w()});w()}(window);
</script>

View File

@ -1,26 +0,0 @@
export interface BaseProps {
className?: string;
style?: React.CSSProperties;
children?: React.ReactNode;
}
export interface Pagination {
total: number;
size: number;
index: number;
length: number;
beginIndex: number;
endIndex: number;
}
export interface BaseResponse {
code: string;
msg: string;
memo: string;
data: any;
pagination?: Pagination;
result: number;
success: boolean;
requestId: string;
linkTime: number;
}

View File

@ -1,3 +1,3 @@
export default {
navigationBarTitleText: '首页',
};
export default definePageConfig({
navigationBarTitleText: '首页'
})

View File

@ -1,4 +0,0 @@
.container {
width: 400px;
margin: 0 auto;
}

View File

View File

@ -1,25 +1,24 @@
import React from 'react';
import { View, Text } from '@tarojs/components';
import { AtButton } from 'taro-ui';
import Demo from '@/components/Demo';
import styles from './index.module.scss';
import { chooseImage } from '@/utils';
import { Component } from 'react'
import { View, Text } from '@tarojs/components'
import './index.styl'
const Index: Taro.FC = () => {
const upload = async () => {
const res = await chooseImage();
console.log(res);
};
export default class Index extends Component {
return (
<View className={styles.container}>
<Text>Hello world!</Text>
<Demo />
<AtButton type="primary" onClick={upload}>
AtButton
</AtButton>
</View>
);
};
componentWillMount () { }
export default Index;
componentDidMount () { }
componentWillUnmount () { }
componentDidShow () { }
componentDidHide () { }
render () {
return (
<View className='index'>
<Text>Hello world!</Text>
</View>
)
}
}

View File

@ -1,8 +0,0 @@
@import './var.scss';
$color-brand: $S3;
$color-success: $F-green;
$color-error: $F-red;
/* 引入 Taro UI 默认样式 */
@import '~taro-ui/dist/style/index.scss';

View File

@ -1,2 +0,0 @@
@import './custom-variables.scss';
@import './var.scss';

View File

@ -1,441 +0,0 @@
@import './var.scss';
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
margin: 0;
padding: 0;
border: 0;
font: inherit;
font-family: 'PingFang SC', 'Heiti SC', 'Microsoft YaHei', Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
vertical-align: baseline;
box-sizing: border-box;
}
html,
body {
min-height: 100vh;
height: auto;
}
/* make sure to set some focus styles for accessibility */
:focus {
outline: 0;
}
/* HTML5 display-role reset for older browsers */
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
display: block;
}
body {
line-height: 1;
}
ol,
ul {
list-style: none;
}
blockquote,
q {
quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
input[type='search']::-webkit-search-cancel-button,
input[type='search']::-webkit-search-decoration,
input[type='search']::-webkit-search-results-button,
input[type='search']::-webkit-search-results-decoration {
-webkit-appearance: none;
-moz-appearance: none;
}
input[type='search'] {
-webkit-appearance: none;
-moz-appearance: none;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
textarea {
overflow: auto;
vertical-align: top;
resize: vertical;
}
/**
* Correct `inline-block` display not defined in IE 6/7/8/9 and Firefox 3.
*/
audio,
canvas,
video {
display: inline-block;
max-width: 100%;
}
/**
* Prevent modern browsers from displaying `audio` without controls.
* Remove excess height in iOS 5 devices.
*/
audio:not([controls]) {
display: none;
height: 0;
}
/**
* Address styling not present in IE 7/8/9, Firefox 3, and Safari 4.
* Known issue: no IE 6 support.
*/
[hidden] {
display: none;
}
/**
* 1. Correct text resizing oddly in IE 6/7 when body `font-size` is set using
* `em` units.
* 2. Prevent iOS text size adjust after orientation change, without disabling
* user zoom.
*/
html {
font-size: 100%; /* 1 */
-webkit-text-size-adjust: 100%; /* 2 */
-ms-text-size-adjust: 100%; /* 2 */
}
/**
* Address `outline` inconsistency between Chrome and other browsers.
*/
a {
text-decoration: none;
}
a:focus {
outline: none;
}
/**
* Improve readability when focused and also mouse hovered in all browsers.
*/
a:active,
a:hover {
outline: 0;
}
/**
* 1. Remove border when inside `a` element in IE 6/7/8/9 and Firefox 3.
* 2. Improve image quality when scaled in IE 7.
*/
img {
border: 0; /* 1 */
-ms-interpolation-mode: bicubic; /* 2 */
}
/**
* Address margin not present in IE 6/7/8/9, Safari 5, and Opera 11.
*/
figure {
margin: 0;
}
/**
* Correct margin displayed oddly in IE 6/7.
*/
form {
margin: 0;
}
/**
* Define consistent border, margin, and padding.
*/
fieldset {
border: 1px solid #c0c0c0;
margin: 0 2px;
padding: 0.35em 0.625em 0.75em;
}
/**
* 1. Correct color not being inherited in IE 6/7/8/9.
* 2. Correct text not wrapping in Firefox 3.
* 3. Correct alignment displayed oddly in IE 6/7.
*/
legend {
border: 0; /* 1 */
padding: 0;
white-space: normal; /* 2 */
}
/**
* 1. Correct font size not being inherited in all browsers.
* 2. Address margins set differently in IE 6/7, Firefox 3+, Safari 5,
* and Chrome.
* 3. Improve appearance and consistency in all browsers.
*/
button,
input,
select,
textarea {
font-size: 100%; /* 1 */
margin: 0; /* 2 */
vertical-align: baseline; /* 3 */
}
/**
* Address Firefox 3+ setting `line-height` on `input` using `!important` in
* the UA stylesheet.
*/
button,
input {
line-height: normal;
}
/**
* Address inconsistent `text-transform` inheritance for `button` and `select`.
* All other form control elements do not inherit `text-transform` values.
* Correct `button` style inheritance in Chrome, Safari 5+, and IE 6+.
* Correct `select` style inheritance in Firefox 4+ and Opera.
*/
button,
select {
text-transform: none;
}
/**
* 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
* and `video` controls.
* 2. Correct inability to style clickable `input` types in iOS.
* 3. Improve usability and consistency of cursor style between image-type
* `input` and others.
* 4. Remove inner spacing in IE 7 without affecting normal text inputs.
* Known issue: inner spacing remains in IE 6.
*/
button,
html input[type="button"], /* 1 */
input[type="reset"],
input[type="submit"] {
-webkit-appearance: button; /* 2 */
cursor: pointer; /* 3 */
}
/**
* Re-set default cursor for disabled elements.
*/
button[disabled],
html input[disabled] {
cursor: default;
}
/**
* 1. Address box sizing set to content-box in IE 8/9.
* 2. Remove excess padding in IE 8/9.
* 3. Remove excess padding in IE 7.
* Known issue: excess padding remains in IE 6.
*/
input[type='checkbox'],
input[type='radio'] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/**
* 1. Address `appearance` set to `searchfield` in Safari 5 and Chrome.
* 2. Address `box-sizing` set to `border-box` in Safari 5 and Chrome
* (include `-moz` to future-proof).
*/
input[type='search'] {
-webkit-appearance: textfield; /* 1 */
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box; /* 2 */
box-sizing: content-box;
}
/**
* Remove inner padding and search cancel button in Safari 5 and Chrome
* on OS X.
*/
input[type='search']::-webkit-search-cancel-button,
input[type='search']::-webkit-search-decoration {
-webkit-appearance: none;
}
/**
* Remove inner padding and border in Firefox 3+.
*/
button::-moz-focus-inner,
input::-moz-focus-inner {
border: 0;
padding: 0;
}
/**
* 1. Remove default vertical scrollbar in IE 6/7/8/9.
* 2. Improve readability and alignment in all browsers.
*/
textarea {
overflow: auto; /* 1 */
vertical-align: top; /* 2 */
}
/**
* Remove most spacing between table cells.
*/
table {
border-collapse: collapse;
border-spacing: 0;
}
html,
button,
input,
select,
textarea {
color: #222;
}
::-moz-selection {
background: #b3d4fc;
text-shadow: none;
}
::selection {
background: #b3d4fc;
text-shadow: none;
}
img {
vertical-align: middle;
}
fieldset {
border: 0;
margin: 0;
padding: 0;
}
textarea {
resize: vertical;
}

View File

@ -1,93 +0,0 @@
/* UI 规范 */
/* 颜色 */
$S1: #002952;
$S2: #106ecc;
$S3: #148aff;
$S4: #5cadff;
$S5: #85c2ff;
$S6: #cce6ff;
$M1: #0e1114;
$M2: #33383d;
$M3: #565e66;
$M4: #83898f;
$M5: #bfc3c7;
$M6: #e6e8eb;
$M7: #f0f2f5;
$M8: #fafbfc;
$M9: #ffffff;
$M10: #000000;
$D1: #fac105;
$D2: #ffab24;
$D3: #ff6952;
$D4: #ff3c73;
$D5: #ee62d5;
$D6: #8475ff;
$D7: #4f73ff;
$D8: #2e9cff;
$D9: #0cc0c9;
$D10: #0cc991;
$D11: #83d615;
$D1-1: #fef8e5;
$D2-1: #fff6e9;
$D3-1: #fff0ed;
$D4-1: #ffebf1;
$D5-1: #fdeffa;
$D6-1: #f2f1ff;
$D7-1: #edf1ff;
$D8-1: #eaf5ff;
$D9-1: #e6f8f9;
$D10-1: #e6f9f3;
$D11-1: #f2fae7;
$F-blue: #29b8ff;
$F-green: #46cf84;
$F-yellow: #ffa42e;
$F-red: #ff475a;
/* 字体 */
$Fs-1: 12px;
$Fs-2: 14px;
$Fs-3: 16px;
$Fs-4: 18px;
$Fs-5: 20px;
$Fs-6: 22px;
$Fs-7: 24px;
$Fs-8: 28px;
$Fs-9: 32px;
/* 行高 */
$Lh-1: 20px;
$Lh-2: 22px;
$Lh-3: 24px;
$Lh-4: 26px;
$Lh-5: 28px;
$Lh-6: 30px;
$Lh-7: 32px;
$Lh-8: 36px;
$Lh-9: 42px;
/* 间距 */
$Sp-1: 2px;
$Sp-2: 4px;
$Sp-3: 8px;
$Sp-4: 10px;
$Sp-5: 12px;
$Sp-6: 16px;
$Sp-7: 20px;
$Sp-8: 24px;
$Sp-9: 30px;
$Sp-10: 32px;
$Sp-11: 40px;
/* 阴影 */
$Sh-1: 0 0 8px 0 rgba(0, 0, 0, 0.05);
$Sh-2: 0 2px 8px 0 rgba(0, 0, 0, 0.1);
$Sh-3: 0 0 12px 0 rgba(0, 0, 0, 0.1);
$Sh-4: -4px 0 20px 0 rgba(0, 0, 0, 0.1);
$Sh-5: 0 2px 20px 0 rgba(0, 0, 0, 0.3);
/* 圆角 */
$Ra-1: 2px;
$Ra-2: 3px;
$Ra-3: 6px;
$Ra-4: 10px;
/* $Ra-5: (元素高的一半) / 50% */

View File

@ -1,26 +0,0 @@
/**
*
*/
import Taro from '@tarojs/taro';
export enum CacheKey {
Key = 'key',
}
export class Cache {
static get(key: CacheKey) {
return Taro.getStorageSync(key);
}
static set(key: CacheKey, data: any, isSync = false) {
if (isSync) {
Taro.setStorage({ key, data });
} else {
Taro.setStorageSync(key, data);
}
}
static remove(key: CacheKey) {
Taro.removeStorageSync(key);
}
}

View File

@ -1,16 +0,0 @@
import Taro from '@tarojs/taro';
/**
*
* @param path
* @returns
*/
export const initVoice = (path: string) => {
let voiceContext: Taro.InnerAudioContext = {} as any;
voiceContext = Taro.createInnerAudioContext();
voiceContext.src = path;
voiceContext.onEnded(() => {
voiceContext.destroy();
});
return voiceContext;
};

View File

@ -1,34 +0,0 @@
import { useState, useEffect } from 'react';
import { Events } from '@tarojs/taro';
const globalEvent = new Events();
// 通知事件key
export enum EventsKey {
Demo = 'demo',
}
// 监听和关闭事件的hooks
export const useEvents = (
key: EventsKey,
listener: (info?: any) => void,
isUse = true,
) => {
// 监听事件实例;
const [eventInstance, setEventInstance] = useState<any>();
useEffect(() => {
if (isUse) {
const event = globalEvent.on(key, listener);
setEventInstance(event);
}
return () => {
eventInstance && globalEvent.off(key);
};
}, []);
};
// 通知方法
export const triggerEvent = (key: EventsKey, info?: any) => {
globalEvent.trigger(key, info);
};

View File

@ -1,122 +0,0 @@
import { Toast } from '@/utils/toast';
import Taro from '@tarojs/taro';
import { Loading } from './loading';
/**
*
* @param option http://taro-docs.jd.com/taro/docs/apis/media/image/chooseImage/
* @returns Promise<any>
*/
export const chooseImage = (option?: Taro.chooseImage.Option): Promise<any> => {
const { count = 1, sourceType = ['album', 'camera'], ...rest } = option || {};
return new Promise((resolve, reject) => {
Taro.chooseImage({
count,
sourceType,
...rest,
sizeType: ['compressed'],
success: (res) => {
resolve(res);
},
fail: (e) => {
reject(e);
},
});
});
};
/**
*
* @param option https://taro-docs.jd.com/taro/docs/apis/network/upload/uploadFile
* @returns Promise<any>
*/
export const uploadFile = (option: Taro.uploadFile.Option): Promise<any> => {
Loading.show();
return new Promise((resolve, reject) => {
Taro.uploadFile({
...option,
success(res) {
if (res.statusCode === 200 && res.data) {
const data = JSON.parse(res.data);
resolve(data.success ? data.data : false);
} else {
resolve(true);
}
},
fail(e) {
Toast.info('上传失败');
reject(e);
},
complete() {
Loading.hide();
},
});
});
};
/**
* OSS
* @param superKey superKey
* @returns
*/
export const getSignature = async (superKey: string) => {
try {
const params = { superKey };
// TODO: 根据业务修改获取 signature 方法
// const res = await fn(params);
const res: any = { ...params, success: true };
if (res.success) {
return res.data;
}
} catch (err) {
console.log(err);
}
};
/**
* OSS
* @param tempFile
* @param superKey OSS superKey
* @returns OSS
*/
export const uploadOSS = async (
tempFile: Taro.chooseImage.ImageFile | Taro.chooseMessageFile.ChooseFile,
superKey: string,
) => {
// 获取上传oss参数
const oss = await getSignature(superKey);
if (oss) {
// 无法获取图片名称,采用时间戳作为文件名
const fileName = (tempFile as any)?.name
// BUG
? `${+new Date()}`
: `${+new Date()}`;
const key = `${superKey}/${fileName}`;
const { dir, policy, accessId: OSSAccessKeyId, signature, host } = oss;
try {
// 上传至 oss
const res = await uploadFile({
url: host,
name: fileName,
filePath: tempFile.path,
formData: {
dir,
policy,
OSSAccessKeyId,
signature,
key,
success_action_status: '200',
},
});
if (res) {
// 返回文件地址
return `${host}/${key}`;
} else {
Toast.info('上传失败');
}
} catch (e) {
console.log('e', e);
}
}
};

View File

@ -1,6 +0,0 @@
export { initVoice } from './common';
export { Cache, CacheKey } from './cache';
export { Toast } from './toast';
export { useEvents, EventsKey } from './event';
export { chooseImage, uploadFile } from './file';
export { Loading } from './loading';

View File

@ -1,16 +0,0 @@
import Taro from '@tarojs/taro';
export class Loading {
static show(option?: Partial<Taro.showLoading.Option>) {
const { title = 'loading...', mask = true, ...rest } = option || {};
Taro.showLoading({
title,
mask,
...rest,
});
}
static hide() {
Taro.hideLoading();
}
}

View File

@ -1,50 +0,0 @@
import Taro from '@tarojs/taro';
import { BaseResponse } from '@/interface/base';
import CodeMsg from '@/assets/data/code.json';
export const DEFAULT_TIP_MESSAGE = '请求失败,请刷新重试';
/**
*
* @param {Object} data
*/
export function handleError(data) {
const message = CodeMsg[data.code] || data.msg || DEFAULT_TIP_MESSAGE;
Taro.atMessage({
message,
type: 'error',
});
}
const request = (options) => {
return new Promise<BaseResponse>((resolve, reject) => {
Taro.request({
timeout: 5000,
mode: 'cors',
success(res) {
const { data } = res;
if (!data.success) {
handleError(data);
}
resolve(data);
},
fail(err) {
Taro.atMessage({ message: DEFAULT_TIP_MESSAGE, type: 'error' });
reject(err);
// for debug
console.log(err);
},
...options,
header: {
'content-type': 'application/json', // 默认值
token: Taro.getStorageSync('token'),
...options.header,
},
url: `${process.env.BASE_URL || ''}${process.env.BASE_API || ''}${
options.url || ''
}`,
});
});
};
export default request;

View File

@ -1,85 +0,0 @@
import Taro from '@tarojs/taro';
const DEFAULT_TOAST_TIME = 3000;
// 文档
// showToast http://taro-docs.jd.com/taro/docs/apis/ui/interaction/showToast/
// showModal: http://taro-docs.jd.com/taro/docs/apis/ui/interaction/showModal/
export class Toast {
static info(msg: string, option?: Taro.showToast.Option) {
const {
title,
icon,
duration = DEFAULT_TOAST_TIME,
...rest
} = option || {};
Taro.showToast({
icon: 'none',
title: msg,
duration,
...rest,
});
}
static success(msg: string, option?: Taro.showToast.Option) {
const {
title,
icon,
duration = DEFAULT_TOAST_TIME,
...rest
} = option || {};
Taro.showToast({
title: msg,
icon: 'success',
duration,
...rest,
});
}
static alert({
title = '提示',
showCancel,
success,
fail,
...rest
}: Taro.showModal.Option) {
Taro.showModal({
title,
showCancel: false,
success: (res) => {
if (res.confirm) {
success && success(res);
}
},
...rest,
});
}
static confirm({
confirmText = '确定',
cancelText = '取消',
success,
fail,
showCancel,
confirmColor = '#16953C',
...rest
}: Taro.showModal.Option) {
Taro.showModal({
confirmText,
cancelText,
showCancel: true,
confirmColor,
success: (res) => {
if (res.confirm) {
success && success(res);
} else if (res.cancel) {
fail && fail(res);
}
},
...rest,
});
}
}
// export default Toast;

View File

@ -14,16 +14,14 @@
"strictNullChecks": true,
"sourceMap": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
"rootDir": ".",
"jsx": "react",
"jsxFactory": "React.createElement",
"jsx": "react-jsx",
"allowJs": true,
"resolveJsonModule": true,
"typeRoots": ["node_modules/@types", "global.d.ts"]
"typeRoots": [
"node_modules/@types"
]
},
"exclude": ["node_modules", "dist"],
"include": ["./src", "global.d.ts"],
"compileOnSave": false
}

12687
yarn.lock

File diff suppressed because it is too large Load Diff