美文网首页
一些样式整理及总结

一些样式整理及总结

作者: 五号社会好青年 | 来源:发表于2022-04-07 12:08 被阅读0次

整个项目已经传到了gitee上面,https://gitee.com/malahaha/pjingdongdaojia.git

全部页面如下
登陆界面.png 订单.png 首页.png 下单1.png 下单2.png 详情1.png 详情2.png 详情3.png 详情4.png 详情5.png 注册界面.png

上述几篇文章中的一些样式为了方便后期维护,将它们全部封装成一个文件在style文件夹中,

(1)mixin.scss

//单行文本超出省略
@mixin ellipsis{
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

(2)variable.scss一些通用颜色样式

$content-fontcolor:#333;
$light-fontColor:#999;
$medium-fontColor:#666;
$dark-fontColor:#000;
$content-bgcolor:#F1F1F1;
$content-notice-fontcolor:#777;
$search-bgColor:#f5f5f5;
$search-fontColor:#b7b7b7;
$bgColor:#fff;
$highlight-fontColor:#E93B3B;
$btn-bgColor:#0091ff;

(3)iconfont小图标的使用

@font-face {
  font-family: 'iconfont';  /* Project id 3220603 */
  src: url('//at.alicdn.com/t/font_3220603_9vci4ti956.woff2?t=1648890516449') format('woff2'),
       url('//at.alicdn.com/t/font_3220603_9vci4ti956.woff?t=1648890516449') format('woff'),
       url('//at.alicdn.com/t/font_3220603_9vci4ti956.ttf?t=1648890516449') format('truetype');
}
  
  .iconfont {
    font-family: "iconfont" !important;
    font-size: .16rem;
    font-style: normal;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

(4)vuex中数据获取和一些数据变更功能实现

import { createStore } from 'vuex'

const setLocalCartList = (state)=>{
  const { cartList } = state;
  const cartListString = JSON.stringify(cartList);
  localStorage.cartList = cartListString;
}
const getLocalCartList = ()=>{
  try{
    return JSON.parse(localStorage.cartList) || {}
  }catch(e){
    return {}
  }
}

export default createStore({
  state: {
    // cartList:{
    //   shopId:{
    //     shopNme:'沃尔玛',
    //     productList:{
    //        productId:{
    //          _id: "1",
    //          name: "番茄 250g / 份",
    //          imgUrl: "http://www.dell-lee.com/imgs/vue3/tomato.png",
    //          sales: 10,
    //          price: 33.6,
    //          oldPrice: 39.6,
    //          count:2
    //        } 
    //     }
    // }
    // cartList:{}
    cartList:getLocalCartList()
  },
  getters: {
  },
  mutations: {
    changeCartItemInfo(state,pyload){
      const {shopId,productId,productInfo} = pyload;
      let shopInfo = state.cartList[shopId] || {
        shopName:'',
        productList:{}
      };
      // if(!shopInfo) {shopInfo={}}
      let product = shopInfo.productList[productId];
      if(!product) { 
        productInfo.count = 0;
        product=productInfo;
        // product.count = 0;
      }
      product.count = product.count +pyload.num;

      if(pyload.num > 0){product.check = true;}
      // 等价于
      // (pyload.num > 0) && (product.check = true);
    
      if(product.count < 0) {product.count = 0;}
      // 等价于
      // (product.count < 0) && (product.count = 0);

      shopInfo.productList[productId] = product;
      state.cartList[shopId] = shopInfo;

      setLocalCartList(state);
    },

    changeShopName(state,pyload){
      const {shopId,shopName} = pyload;
      const shopInfo = state.cartList[shopId] || {
        shopName:'',
        productList:{}
      }
      shopInfo.shopName=shopName;
      state.cartList[shopId] = shopInfo

      setLocalCartList(state);
    },

    changeCartItemChecked(state,pyload){
      const {shopId,productId} = pyload;
      const product = state.cartList[shopId].productList[productId];
      //console.log(product)
       product.check = !product.check;

       setLocalCartList(state);
    },

    cleanCartProducts(state,pyload){
      const {shopId} = pyload;
      state.cartList[shopId].productList={};
    },

    setCartItemsChecked(state,pyload){
      const {shopId} = pyload;
      const products = state.cartList[shopId].productList;
      if(products){
        for(let i in products){
          const product =products[i];
          product.check = true;
          
        }
      }
      setLocalCartList(state);
    },

    clearCartData(state,pyload){
      const {shopId} = pyload
      state.cartList[shopId].productList=[];
    }
  },
})

(5)路由实现router文件夹下的index.js

import { createRouter, createWebHashHistory } from 'vue-router'
const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import(/* webpackChunkName: "home" */ '../views/home/HomeV')
  },
  {
    path: '/cartList',
    name: 'CartList',
    component: () => import(/* webpackChunkName: "cartList" */ '../views/cartList/CartList')
  },
  {
    path: '/orderConfirmation/:id',
    name: 'OrderConfirmation',
    component: () => import(/* webpackChunkName: "orderConfirmation" */ '../views/orderConfirmation/OrderConfirmation')
  },
  {
    path: '/orderList',
    name: 'OrderList',
    component: () => import(/* webpackChunkName: "orderList" */ '../views/orderList/OrderList')
  },
  {
    path: '/shop/:id',
    name: 'Shop',
    component: () => import(/* webpackChunkName: "shop" */ '../views/shop/ShopV')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "login" */ '../views/login/LoginV'),
    beforeEnter(to,from,next){
      const {isLogin} =localStorage;
      isLogin ? next({name:"Home"}) : next();
    },
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import(/* webpackChunkName: "register" */ '../views/register/RegisterV'),
    beforeEnter(to,from,next){
      const {isLogin} =localStorage;
      isLogin ? next({name:"Home"}) : next();
    },
  },
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to,from,next) => {
  const {isLogin }= localStorage;
  const {name} = to;
  const isLoginOrRegister = (name === "Login" || name === "Register");

  (isLogin || isLoginOrRegister) ? next() : next({name:'Login'});
})

export default router

*若是一个界面要使用一些对应的数据,功能或者样式,一定要记得引入文件

相关文章

  • 一些样式整理及总结

    整个项目已经传到了gitee上面,https://gitee.com/malahaha/pjingdongdaoj...

  • iOS-UITextField 回顾总结

    UITextField的一些坑总结 点击进入 初始化textfield并设置位置及大小 设置边框样式,只有设置了才...

  • 2017.8.28

    继之前的行间样式 内联样式之后 今天学习了外联样式 看起来更加简便 好整理 好对比 好修改 公用元素不错 总结...

  • 《Flutter For Android学习日记》文本及样式

    一、文本及样式 1.Text Text用于显示简单样式文本,它包含一些控制文本显示样式的一些属性,一个简单的例子如...

  • 原生JS获取及设置CSS样式-1.行内样式

    面试中,应该会经常被问到样式的写法以及如何使用原生JS获取及操作样式的问题吧,让我给大家总结一下~ HTML中样式...

  • 单元测试之如何编写优秀的单元测试用例

    这篇文章是结合"The Art of Unit Testing"一书及业内一些单元测试大牛们的总结整理而成。主要内...

  • html & css学习第二周总结(下)

    接前天的总结,下部分主要整理下文本格式化的内容,包括单位、字体样式、文本样式。这些理解上没有什么难度,主要是多练记...

  • 九月第三周学习笔记分享

    整理 代码/整理 术语整理 代码/整理 CSS:层叠样式表 CSS中的元素样式设置叫做类选择器:.be-text{...

  • 项目梳理计划

    一、项目分类及概述(已完成) 二、项目的卖点及策划过程总结(整理文件夹→看报告理大纲→要点及关键点总结→未解决的问...

  • css 常用的一些样式整理

    1。 文字一行显示超出省略号显示 display: inline-block; width: 80%; whi...

网友评论

      本文标题:一些样式整理及总结

      本文链接:https://www.haomeiwen.com/subject/gdeksrtx.html