项目作者: mystic3333

项目描述 :
用react写的一个webapp demo, 只写了一部分
高级语言: JavaScript
项目地址: git://github.com/mystic3333/react_goodlive_program.git
创建时间: 2020-07-07T12:58:24Z
项目社区:https://github.com/mystic3333/react_goodlive_program

开源协议:

下载


参考资料汇总

  1. - 字体图标库: https://icomoon.io/
  2. - iconfont: https://www.iconfont.cn/
  3. - 蓝湖psd稿设计软件: https://lanhuapp.com/

项目初始化

  1. npx create-react-app goodlive

拉取配置文件

  1. npm run eject

配置less

  1. npm install less less-loader --save
  1. const lessRegex = /\.less$/;
  2. module: {
  3. {
  4. test: lessRegex,
  5. exclude: lessModuleRegex,
  6. use: getStyleLoaders(
  7. {
  8. importLoaders: 3,
  9. sourceMap: isEnvProduction && shouldUseSourceMap,
  10. },
  11. 'less-loader'
  12. ),
  13. // Don't consider CSS imports dead code even if the
  14. // containing package claims to have no side effects.
  15. // Remove this when webpack adds a warning or an error for this.
  16. // See https://github.com/webpack/webpack/issues/6571
  17. sideEffects: true,
  18. }
  19. }

初始化css

reset.less文件

  1. @charset "gb2312";
  2. /* CSS Document */
  3. html,body,h1,h2,h3,h4,h5,h6,div,dl,dt,dd,ul,ol,li,p,blockquote,pre,hr,figure,table,caption,th,td,form,fieldset,legend,input,button,textarea,menu{margin:0;padding:0;}
  4. body{padding:0; margin:0; background:black;}
  5. html,body,fieldset,img,iframe,abbr{border:0;}
  6. li{list-style:none;}
  7. textarea{overflow:auto;resize:none;}
  8. a,button{cursor:pointer;}
  9. h1,h2,h3,h4,h5,h6,em,strong,b{font-weight:bold;}
  10. a,a:hover{text-decoration:none;}
  11. body,textarea,input,button{
  12. color:#62a1c9;
  13. }
  14. html,body{
  15. width:100%;
  16. min-height: 930px;
  17. height: auto;
  18. }
  19. .hide{
  20. display: none;
  21. }
  22. .text-shadow (@string: 0 1px 3px rgba(0, 0, 0, 0.25)) {
  23. text-shadow: @string;
  24. }
  25. .box-shadow (@string) {
  26. -webkit-box-shadow: @string;
  27. -moz-box-shadow: @string;
  28. box-shadow: @string;
  29. }
  30. .drop-shadow (@x: 0, @y: 1px, @blur: 2px, @spread: 0, @alpha: 0.25) {
  31. -webkit-box-shadow: @x @y @blur @spread rgba(0, 0, 0, @alpha);
  32. -moz-box-shadow: @x @y @blur @spread rgba(0, 0, 0, @alpha);
  33. box-shadow: @x @y @blur @spread rgba(0, 0, 0, @alpha);
  34. }
  35. .inner-shadow (@x: 0, @y: 1px, @blur: 2px, @spread: 0, @alpha: 0.25) {
  36. -webkit-box-shadow: inset @x @y @blur @spread rgba(0, 0, 0, @alpha);
  37. -moz-box-shadow: inset @x @y @blur @spread rgba(0, 0, 0, @alpha);
  38. box-shadow: inset @x @y @blur @spread rgba(0, 0, 0, @alpha);
  39. }
  40. .box-sizing (@type: border-box) {
  41. -webkit-box-sizing: @type;
  42. -moz-box-sizing: @type;
  43. box-sizing: @type;
  44. }
  45. .border-radius (@radius: 5px) {
  46. -webkit-border-radius: @radius;
  47. -moz-border-radius: @radius;
  48. border-radius: @radius;
  49. -moz-background-clip: padding;
  50. -webkit-background-clip: padding-box;
  51. background-clip: padding-box;
  52. }
  53. .border-radiuses (@topright: 0, @bottomright: 0, @bottomleft: 0, @topleft: 0) {
  54. -webkit-border-top-right-radius: @topright;
  55. -webkit-border-bottom-right-radius: @bottomright;
  56. -webkit-border-bottom-left-radius: @bottomleft;
  57. -webkit-border-top-left-radius: @topleft;
  58. -moz-border-radius-topright: @topright;
  59. -moz-border-radius-bottomright: @bottomright;
  60. -moz-border-radius-bottomleft: @bottomleft;
  61. -moz-border-radius-topleft: @topleft;
  62. border-top-right-radius: @topright;
  63. border-bottom-right-radius: @bottomright;
  64. border-bottom-left-radius: @bottomleft;
  65. border-top-left-radius: @topleft;
  66. -moz-background-clip: padding;
  67. -webkit-background-clip: padding-box;
  68. background-clip: padding-box;
  69. }
  70. .opacity (@opacity: 0.5) {
  71. @tempOpacity: @opacity * 100;
  72. -webkit-opacity: @opacity;
  73. -moz-opacity: @opacity;
  74. opacity: @opacity;
  75. filter:alpha(opacity=@tempOpacity);
  76. }
  77. .gradient (@startColor: #eee, @endColor: white) {
  78. background-color: @startColor;
  79. background: -webkit-gradient(linear, left top, left bottom, from(@startColor), to(@endColor));
  80. background: -webkit-linear-gradient(top, @startColor, @endColor);
  81. background: -moz-linear-gradient(top, @startColor, @endColor);
  82. background: -ms-linear-gradient(top, @startColor, @endColor);
  83. background: -o-linear-gradient(top, @startColor, @endColor);
  84. }
  85. .horizontal-gradient (@startColor: #eee, @endColor: white) {
  86. background-color: @startColor;
  87. background-image: -webkit-gradient(linear, left top, right top, from(@startColor), to(@endColor));
  88. background-image: -webkit-linear-gradient(left, @startColor, @endColor);
  89. background-image: -moz-linear-gradient(left, @startColor, @endColor);
  90. background-image: -ms-linear-gradient(left, @startColor, @endColor);
  91. background-image: -o-linear-gradient(left, @startColor, @endColor);
  92. background-image: linear-gradient(left, @startColor, @endColor);
  93. }
  94. .animation (@name, @duration: 300ms, @delay: 0, @ease: ease) {
  95. -webkit-animation: @name @duration @delay @ease;
  96. -moz-animation: @name @duration @delay @ease;
  97. -ms-animation: @name @duration @delay @ease;
  98. animation: @name @duration @delay @ease;
  99. }
  100. .transition (@transition) {
  101. -webkit-transition: @transition;
  102. -moz-transition: @transition;
  103. -ms-transition: @transition;
  104. -o-transition: @transition;
  105. transition: @transition;
  106. }
  107. .transform(@string){
  108. -webkit-transform: @string;
  109. -moz-transform: @string;
  110. -ms-transform: @string;
  111. -o-transform: @string;
  112. transform: @string;
  113. }
  114. .scale (@factor) {
  115. -webkit-transform: scale(@factor);
  116. -moz-transform: scale(@factor);
  117. -ms-transform: scale(@factor);
  118. -o-transform: scale(@factor);
  119. transform: scale(@factor);
  120. }
  121. .rotate (@deg) {
  122. -webkit-transform: rotate(@deg);
  123. -moz-transform: rotate(@deg);
  124. -ms-transform: rotate(@deg);
  125. -o-transform: rotate(@deg);
  126. transform: rotate(@deg);
  127. }
  128. .skew (@deg, @deg2) {
  129. -webkit-transform: skew(@deg, @deg2);
  130. -moz-transform: skew(@deg, @deg2);
  131. -ms-transform: skew(@deg, @deg2);
  132. -o-transform: skew(@deg, @deg2);
  133. transform: skew(@deg, @deg2);
  134. }
  135. .translate (@x, @y:0) {
  136. -webkit-transform: translate(@x, @y);
  137. -moz-transform: translate(@x, @y);
  138. -ms-transform: translate(@x, @y);
  139. -o-transform: translate(@x, @y);
  140. transform: translate(@x, @y);
  141. }
  142. .translate3d (@x, @y: 0, @z: 0) {
  143. -webkit-transform: translate3d(@x, @y, @z);
  144. -moz-transform: translate3d(@x, @y, @z);
  145. -ms-transform: translate3d(@x, @y, @z);
  146. -o-transform: translate3d(@x, @y, @z);
  147. transform: translate3d(@x, @y, @z);
  148. }
  149. .perspective (@value: 1000) {
  150. -webkit-perspective: @value;
  151. -moz-perspective: @value;
  152. -ms-perspective: @value;
  153. perspective: @value;
  154. }
  155. .transform-origin (@x:center, @y:center) {
  156. -webkit-transform-origin: @x @y;
  157. -moz-transform-origin: @x @y;
  158. -ms-transform-origin: @x @y;
  159. -o-transform-origin: @x @y;
  160. transform-origin: @x @y;
  161. }
  162. .keyframes(@name, @frames) {
  163. @-webkit-keyframes @name { @frames(); }
  164. @-moz-keyframes @name { @frames(); }
  165. @-ms-keyframes @name { @frames(); }
  166. @-o-keyframes @name { @frames(); }
  167. @keyframes @name { @frames(); }
  168. }
  169. .animation(@arg){
  170. -moz-animation:@arg;
  171. -webkit-animation:@arg;
  172. -o-animation:@arg;
  173. -ms-animation:@arg;
  174. animation:@arg;
  175. }

reset.css文件

  1. /*reset.css用来存储清除浏览器的样式 ,后面添加了一部分通用样式*/
  2. a { background-color: transparent; text-decoration: none;-webkit-tap-highlight-color:rgba(0,0,0,0) }
  3. a:hover { outline: none; text-decoration: none; }
  4. a,a:hover,a:active,a:visited,a:link,a:focus{
  5. -webkit-tap-highlight-color:rgba(0,0,0,0);
  6. -webkit-tap-highlight-color: transparent;
  7. outline:none;
  8. text-decoration: none;
  9. -webkit-tap-highlight-color:rgba(0,0,0,0);
  10. -webkit-user-modify: read-only;
  11. cursor: pointer;
  12. }
  13. body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, button, textarea, p, blockquote, th, td { margin: 0; padding: 0; }
  14. table { border-collapse: collapse; border-spacing: 0; }
  15. fieldset, img { border: 0; }
  16. address, caption, cite, code, dfn, em, strong, th, var, optgroup { font-style: inherit; font-weight: inherit; }
  17. del, ins { text-decoration: none; }
  18. li { list-style: none; }
  19. caption, th { text-align: left; }
  20. h1, h2, h3, h4, h5, h6 { font-size: 100%; font-weight: normal; }
  21. q:before, q:after { content: ''; }
  22. abbr, acronym { border: 0; font-variant: normal; }
  23. sup { vertical-align: baseline; }
  24. sub { vertical-align: baseline; }
  25. /*because legend doesn't inherit in IE */
  26. legend { color: #000; }
  27. input, button, textarea, select, optgroup, option { font-family: inherit; font-size: inherit; font-style: inherit; font-weight: inherit; }
  28. button, html input[type="button"], input[type="reset"], input[type="submit"] { -webkit-appearance: button; cursor: pointer; }
  29. /*@purpose To enable resizing for IE */
  30. /*@branch For IE6-Win, IE7-Win */
  31. input, button, textarea, select {
  32. *font-size: 100%; outline:none; }
  33. /*select*/
  34. select{
  35. /*复写Chrome和Firefox里面的边框*/
  36. border:1px solid green;
  37. /*清除默认样式*/
  38. appearance:none;
  39. -moz-appearance:none;
  40. -webkit-appearance:none;
  41. /*在选择框的最右侧中间显示小箭头图片*/
  42. /*background: url(../img/icon/icon_select.png) no-repeat scroll right center transparent;*/
  43. /*为下拉小箭头留出一点位置,避免被文字覆盖*/
  44. padding-right: 14px;
  45. }
  46. /*清除ie的默认选择框样式清除,隐藏下拉箭头*/
  47. select::-ms-expand { display: none; }
  48. /* 个人在后面添加了一些常用的公共样式 */
  49. /*居中效果*/
  50. .margin_center { margin: 0px auto; }
  51. /*浮动*/
  52. .float_left { float: left; }
  53. .float_right { float: right; }
  54. /*文字位置*/
  55. .text_center { text-align: center; }
  56. .text_left { text-align: left; }
  57. .text_right { text-align: right; }
  58. /*position*/
  59. .position_relative { position: relative; }
  60. .position_absolute { position: absolute; }
  61. /*边框*/
  62. .no_border { border: 0px!important;border-right: 0px!important; }
  63. /*宽度*/
  64. .width_whole { width: 100%; }
  65. /*清除格式*/
  66. .clear_both { clear: both; }
  67. .no_margin { margin: 0px!important; }
  68. /* 展示样式 */
  69. .display_block { display: block; }
  70. .display_none { display: none; }
  71. .visibility_hidden { visibility: hidden; }
  72. /*清除浮动*/
  73. .clearfix:after {content: "";display: block;height: 0;clear: both;visibility: hidden;}
  74. * html .clearfix{zoom:1;} /* IE6 */
  75. *+html .clearfix{zoom:1;} /* IE7 */
  76. body {
  77. font-family: 'PingFangSC','helvetica neue','hiragino sans gb','arial','microsoft yahei ui','microsoft yahei','simsun','sans-serif'!important;
  78. font-size: 10px;
  79. }

字体自适应

复制到index.html文件中

  1. <script>
  2. (function (width) {
  3. var doc = width.document,
  4. element = doc.documentElement,
  5. i = 640,
  6. d = i / 100,
  7. o = "orientationchange" in width ? "orientationchange" : "resize",
  8. a = function () {
  9. var width = element.clientWidth || 320;
  10. width > 640 && (width = 640);
  11. element.style.fontSize = width / d + "px"
  12. };
  13. doc.addEventListener && (width.addEventListener(o, a, !1), doc.addEventListener("DOMContentLoaded", a, !1))
  14. })(window);
  15. </script>

项目初始化遇到的问题

  1. Cannot find module 'resolve'
  2. 解决方案: 重新安装依赖
  3. 删除 /node_modules
  4. npm clean cache
  5. npm install
  6. npm start 重启服务
  7. 以上操作完美解决了问题

蓝湖 + ps 设计psd项目稿

  1. 参考链接: https://lanhuapp.com/
  2. 下载ps
  3. 备注: 如何使用自己去摸索

配置导航组件Nav

  1. 安装: npm install react-router-dom --save
  1. import React from 'react'
  2. import {HashRouter as Router, Route, Switch} from 'react-router-dom'
  3. import Home from '../pages/Home/home'
  4. import Shop from '../pages/Shop/shop'
  5. import Mine from '../pages/Mine/mine'
  6. import Life from '../pages/Life/life'
  7. import NotFound from '../pages/NotFound/notFound'
  8. export default class Nav extends React.Component {
  9. render () {
  10. return (
  11. <Router>
  12. <Switch>
  13. <Route exact path="/" component={Home}></Route>
  14. <Route exact path="/shop" component={Shop}></Route>
  15. <Route exact path="/mine" component={Mine}></Route>
  16. <Route exact path="/life" component={Life}></Route>
  17. <Route path="*" component={NotFound}></Route>
  18. </Switch>
  19. </Router>
  20. )
  21. }
  22. }

轮播图

github地址: https://github.com/oliviertassinari/react-swipeable-views(点的样式和逻辑需要自己实现)

文档地址: https://react-swipeable-views.com/getting-started/installation/

自动轮播功能需要安装插件: npm install —save react-swipeable-views-utils(具体代码实现看文档实现)

安装: npm install —save react-swipeable-views

  1. import React from 'react';
  2. import SwipeableViews from 'react-swipeable-views';
  3. const styles = {
  4. slide: {
  5. padding: 15,
  6. minHeight: 100,
  7. color: '#fff',
  8. },
  9. slide1: {
  10. background: '#FEA900',
  11. },
  12. slide2: {
  13. background: '#B3DC4A',
  14. },
  15. slide3: {
  16. background: '#6AC0FF',
  17. },
  18. };
  19. const MyComponent = () => (
  20. <SwipeableViews>
  21. <div style={Object.assign({}, styles.slide, styles.slide1)}>
  22. slide n°1
  23. </div>
  24. <div style={Object.assign({}, styles.slide, styles.slide2)}>
  25. slide n°2
  26. </div>
  27. <div style={Object.assign({}, styles.slide, styles.slide3)}>
  28. slide n°3
  29. </div>
  30. </SwipeableViews>
  31. );
  32. export default MyComponent;

搭建一个简易的express服务

参考资料: https://www.expressjs.com.cn/starter/installing.html

安装: npm install express —save
提示: 怎么搭建基本服务和配置路由官方文档都有详细的解释, 这里只是做一个指引.

掌握要点:
路由配置
中间件的使用
整合mysql以及sql的基本操作

  1. const express = require('express')
  2. const app = express()
  3. const router = express.Router()
  4. app.use(router)
  5. app.listen(3001, function(req, res) {
  6. console.log('listening port in 3001')
  7. })

使用redux将城市信息保存在全局store中