当前位置: 首页 > wzjs >正文

建设网站有什么要素构成seo是什么意思 seo是什么职位

建设网站有什么要素构成,seo是什么意思 seo是什么职位,桂林生活网疫情最新消息,axure做的网站可以用吗项目要求实现一键换肤的功能,不仅仅是主题颜色上的替换,还有图片素材的替换,主题颜色替换的方案大同小异,下面仅对图片素材的一件替换进行方法描述。 主要思路 使用本地仓库对当前主题进行存储,系统根据主题去加载不同…

项目要求实现一键换肤的功能,不仅仅是主题颜色上的替换,还有图片素材的替换,主题颜色替换的方案大同小异,下面仅对图片素材的一件替换进行方法描述。

主要思路

使用本地仓库对当前主题进行存储,系统根据主题去加载不同文件夹下的素材文件。

实现方式

1、动态读取文件夹下的图片文件。

注意:不同的素材我们用的是不同文件夹,但是文件名字是一样的,存储位置也是相对统一的,如下图所示。例如:暗色主题下有一个图片地址为bg.jpg,则亮色主题下也需要有一个图片地址为bg.jpg
在这里插入图片描述
编写js/ts对文件内容进行读取并存储,我的文件位置: src/themes.js
注意: import.meta.glob必须是静态字符串,不可设置为动态获取的.

themes.js
// 获取文件夹下所有文件
const images = import.meta.glob(`./assets/themes/light/**/**/*.*`)
const commonImages = import.meta.glob(`./assets/themes/common/**/**/*.*`)let prefix = './assets/themes/light/'
let commonPrefix = './assets/themes/common/'/**** @param {*} imagePaths* @returns*/
const handleFileName = (imagePaths, pathPrefix) => {console.log(imagePaths)let pathObj = {}Object.keys(imagePaths).forEach((key) => {key = key.replace(pathPrefix, '')let pathArr = key.split('/')let length = pathArr.length// 名字let name = pathArr[length - 1]// 文件夹let folder = ''if (length >= 2) {folder = pathArr[length - 2]}// 父文件夹let folderParent = ''if (length >= 3) {folderParent = pathArr[length - 3]}pathObj[key] = {name,folder,folderParent}})return pathObj
}// 获取文件名和文件夹名
let files = handleFileName(images, prefix)
console.log(files)
let commonFiles = handleFileName(commonImages, commonPrefix)const themes = {light: {},dark: {},common: {}
}// 设置不同主题下的图片 文件夹/文件
Object.keys(files).forEach((key) => {let fileObj = files[key]let { name, folder, folderParent } = fileObjlet lightHref = new URL(`./assets/themes/light/${key}`, import.meta.url).hreflet darkHref = new URL(`./assets/themes/dark/${key}`, import.meta.url).hrefif (folderParent) {themes.light[folderParent] ? {} : themes.light[folderParent] = {}themes.light[folderParent][folder] ? {} :themes.light[folderParent][folder]themes.light[folderParent][folder][name] = lightHrefthemes.dark[folderParent] ? {} : themes.dark[folderParent] = {}themes.dark[folderParent][folder] ? {} : themes.dark[folderParent] = {}themes.dark[folderParent][folder][name] = darkHref} else if (folder) {themes.light[folder] ? {} : themes.light[folder] = {}themes.light[folder][name] = lightHrefthemes.dark[folder] ? {} : themes.dark[folder] = {}themes.dark[folder][name] = darkHref} else {themes.light[name] = lightHrefthemes.dark[name] = darkHref}
})// 设置公共图片文件
Object.keys(commonFiles).forEach((key) => {let fileObj = commonFiles[key]let { name, folder, folderParent } = fileObjlet commonHref = new URL(`./assets/themes/common/${key}`, import.meta.url).hrefif (folderParent) {themes.common[folderParent] ? {} : themes.common[folderParent] = {}themes.common[folderParent][folder] = {}themes.common[folderParent][folder][name] = commonHref} else if (folder) {themes.common[folder] ? {} : themes.common[folder] = {}themes.common[folder][name] = commonHref} else {themes.common[name] = commonHref}
})export default themes

2、对项目内的主题(暗色\亮色)进行仓库存储

这里我使用的是pinia进行本地数据存储,我的文件位置src/pinia/modules/theme.ts

import { defineStore } from 'pinia'
import { ref } from 'vue'
import themesImage from '@/themes'const useThemeStore = defineStore('themeStore', () => {let theme = ref('light')const toggleTheme = () => {theme.value = theme.value === 'light' ? 'dark' : 'light'}const getThemeImage = (imgPath: string) => {return getImage(theme.value, imgPath)}const getCommonImage = (imgPath: string) => {return getImage('common', imgPath)}const getImage = (themeName: string, imgPath: string) => {let imagePath = imgPath.split('/')imagePath.lengthif (imagePath.length == 1) {return themesImage[themeName][imagePath[0]]} else if (imagePath.length == 2) {return themesImage[themeName][imagePath[0]][imagePath[1]]} else {return themesImage[themeName][imagePath[0]][imagePath[1]][imagePath[2]]}}return {theme,toggleTheme,getThemeImage,getCommonImage}
})export default useThemeStore

3、编写工具类获取图片地址

编写工具类,便于后续界面读取文件,我的文件地址为: src/utils/themes.ts

import useThemeStore from '@/pinia/modules/theme'
const themeStore = useThemeStore()// 获取主题图片
export const getThemeImage = themeStore.getThemeImage
// 获取公共图片
export const getCommonImage = themeStore.getCommonImage

4、在vue组件中使用

做好准备工作以后,我们只需在组件中引入我们的工具类即可。

<template><div class="container"><img :src="themeUtils.getThemeImage('index/logo.png')" alt="" class="img" /><img :src="themeUtils.getCommonImage('logo.png')" alt="" class="img" /><el-button @click="themeUtils.toggleTheme">一键换肤</el-button></div>
</template><script lang="ts" setup>
import * as themeUtils from '@/utils/themes'
</script><style lang="scss" scoped>
.img{border: 1px solid #ccc;border-radius: 10px;margin-right: 10px;
}
.container{display: flex;align-items: center;
}
</style>

效果如下:
在这里插入图片描述
点击一键换肤以后
在这里插入图片描述

http://www.dtcms.com/wzjs/128948.html

相关文章:

  • 网站建设总结与网络营销公司招聘
  • 建站哪个网站比较好免费网络营销推广软件
  • 新建的网站怎么做seo优化seo外链发布平台
  • 长沙做网站建设公司哪家好西安做网站的网络公司
  • 开装潢公司做网站网站seo应用
  • ps做网站首页设计教程seo搜狗排名点击
  • 渭南汽车网站制作网络seo推广
  • php做网站实例大连seo外包平台
  • 石家庄网站建设报价百度客服电话24小时
  • 消防证怎么考取需要什么条件邯郸seo
  • 旅游类网站模板网络广告策划方案
  • 宝鸡市交通运输局公路建设网站代写文章哪里找写手
  • wordpress标签页面厦门seo怎么做
  • 外贸网站建设有哪些要求网店如何营销推广
  • WordPress 文章最多字潍坊seo培训
  • 网站开发与建设课程设计阿里关键词排名查询
  • 昆明本地网站深圳优化公司样高粱seo
  • 陕西网站建设的内容莆田seo
  • php网站怎么做301跳转关键词搜索排名查询
  • 有没有做奥数题的网站seo优化工作有哪些
  • 网站建设添加视频百度一下搜索网页
  • 想自己建个网站怎么样才能引流客人进店
  • 黄岛区做网站的怎么在百度上做广告推广
  • wordpress非插件幻灯片seo百度贴吧
  • 中国建设银行吉林分行网站商务网站建设
  • 门户网站建设管理情况自查报告什么是搜索引擎竞价推广
  • 网站建设公司盈利企业营销型网站有哪些
  • 网站运营的作用厦门网站搜索引擎优化
  • 如何使用家里电脑做网站服务器查询关键词排名工具
  • 网站设计一般多少钱网页设计作品