Browse Source

dsdfs

master
topuser 5 years ago
parent
commit
8b28cabc3f
  1. 5
      assets/style/_global.scss
  2. 56
      layouts/default.vue
  3. 29
      nuxt.config.js
  4. 5
      package-lock.json
  5. 4
      package.json
  6. 56
      pages/index.vue
  7. 118
      plugins/flexible.js
  8. BIN
      plugins/flexible.js.zip

5
assets/style/_global.scss

@ -25,3 +25,8 @@ img {
max-width: 100%;
height: auto;
}
*{
margin: 0;
padding: 0;
}

56
layouts/default.vue

@ -1,13 +1,36 @@
<template>
<div class="default">
<div id="aside" class="page-sidenav" :class="theme">
<div class="sidenav">
<div class="sidenav h-100">
<div class="logo px-md-4 py-md-4">
<a href="#" class="navbar-brand" style="width:140px;">
<img v-if="theme=='light'" src="https://theme.nicetheme.xyz/lighthouse/wp-content/themes/Lighthouse-1.0.1/images/logo.png" alt="nicetheme">
<img v-if="theme=='dark'" src="https://theme.nicetheme.xyz/lighthouse/wp-content/themes/Lighthouse-1.0.1/images/logo-dark.png" alt="nicetheme">
<img
v-if="theme=='light'"
src="https://theme.nicetheme.xyz/lighthouse/wp-content/themes/Lighthouse-1.0.1/images/logo.png"
alt="nicetheme"
/>
<img
v-if="theme=='dark'"
src="https://theme.nicetheme.xyz/lighthouse/wp-content/themes/Lighthouse-1.0.1/images/logo-dark.png"
alt="nicetheme"
/>
</a>
</div>
<div class="flex-fill scrollable hover py-lg-0">
<ul>
<li class="menu-item">
<div class="nav-link">
<div class="nav-icon">sa</div>
</div>
</li>
<li class="menu-item">
<div class="nav-link">sda</div>
</li>
<li class="menu-item">
<div class="nav-link">sda</div>
</li>
</ul>
</div>
</div>
</div>
<div class="page-content" :class="theme">
@ -22,17 +45,15 @@ export default {
components: {},
mounted() {
console.log(this);
},
computed: {
theme() {
return this.$store.getters.theme
return this.$store.getters.theme;
}
}
};
</script>
<style lang="scss" scoped>
.default {
display: flex;
.page-sidenav {
@ -45,6 +66,29 @@ export default {
&.dark {
background-color: #000000;
}
.sidenav {
display: flex;
flex-direction: column;
.menu-item {
list-style: none;
.nav-link {
position: relative;
font-size: 0.875rem;
padding: 0 0.75rem;
display: -ms-flexbox;
display: flex;
flex-wrap: nowrap;
opacity: 0.6;
.nav-icon{
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
}
}
}
}
}
.page-content {
flex: 1 1 auto !important;

29
nuxt.config.js

@ -14,7 +14,7 @@ module.exports = {
},
{
name: 'viewport',
content: 'width=device-width, initial-scale=1, shrink-to-fit=no'
content: 'width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no'
},
{
hid: 'description',
@ -55,6 +55,7 @@ module.exports = {
** Plugins to load before mounting the App
*/
plugins: [
// { src: "~/plugins/flexible", ssr: false },
'~/plugins/global',
'~/plugins/axios',
'~/plugins/global-components'
@ -62,7 +63,7 @@ module.exports = {
/*
** Nuxt.js dev-modules
*/
devModules: [],
buildModules: [],
/*
** Nuxt.js modules
*/
@ -95,6 +96,30 @@ module.exports = {
config.resolve.alias['@assets'] = path.resolve(__dirname, 'assets');
config.resolve.alias['@components'] = path.resolve(__dirname, 'components');
config.resolve.alias['@images'] = path.resolve(__dirname, 'assets', 'images');
},
postcss: {
// 添加插件名称作为键,参数作为值
// 使用npm或yarn安装它们
plugins: {
// 通过传递 false 来禁用插件
// 'postcss-url': false,
// 'postcss-nested': {},
// 'postcss-responsive-type': {},
// 'postcss-hexrgba': {}
'postcss-pxtorem': {
rootValue: 16,
propList: ['*'],
unitPrecision: 5, //保留小数位
// selectorBlackList: [''], //过滤的类名
// replace: true, //默认直接替换属性
// mediaQuery: false,
minPixelValue: 12 //所有小于设置的样式都不被转换
}
},
preset: {
// 更改postcss-preset-env 设置
autoprefixer: true
}
}
},
serverMiddleware: [

5
package-lock.json

@ -5462,6 +5462,11 @@
"invert-kv": "^1.0.0"
}
},
"lib-flexible": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/lib-flexible/-/lib-flexible-0.3.2.tgz",
"integrity": "sha1-BvWnSDIxSi01wSA5vJw8otrqpCY="
},
"lie": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz",

4
package.json

@ -31,7 +31,9 @@
"vuex-persistedstate": "^2.5.4"
},
"devDependencies": {
"nodemon": "^1.18.9"
"autoprefixer": "^9.7.2",
"nodemon": "^1.18.9",
"postcss-pxtorem": "^4.0.1"
},
"config": {
"nuxt": {

56
pages/index.vue

@ -1,5 +1,7 @@
<template>
<div @click="change">asdsaddsa</div>
<div @click="change">
<input class="switch switch-anim" type="checkbox" checked />//html
</div>
<!-- {{data.category[0]}} -->
</template>
@ -13,11 +15,59 @@ export default {
},
methods: {
change() {
this.$store.dispatch('changeTheme')
this.$store.dispatch("changeTheme");
}
}
};
</script>
<style lang='scss'>
<style lang='scss' scoped>
.switch {
width: 57px;
height: 28px;
position: relative;
border: 1px solid #dfdfdf;
background-color: #fdfdfd;
box-shadow: #dfdfdf 0 0 0 0 inset;
border-radius: 20px;
background-clip: content-box;
display: inline-block;
-webkit-appearance: none;
user-select: none;
outline: none;
}
.switch:before {
content: "";
width: 26px;
height: 26px;
position: absolute;
top: 0;
left: 0;
border-radius: 20px;
background-color: #fff;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.switch:checked {
border-color: #64bd63;
box-shadow: #64bd63 0 0 0 16px inset;
background-color: #64bd63;
}
.switch:checked:before {
left: 30px;
}
.switch.switch-anim {
transition: border cubic-bezier(0, 0, 0, 1) 0.4s,
box-shadow cubic-bezier(0, 0, 0, 1) 0.4s;
}
.switch.switch-anim:before {
transition: left 0.3s;
}
.switch.switch-anim:checked {
box-shadow: #64bd63 0 0 0 16px inset;
background-color: #64bd63;
transition: border ease 0.4s, box-shadow ease 0.4s, background-color ease 1.2s;
}
.switch.switch-anim:checked:before {
transition: left 0.3s;
}
</style>

118
plugins/flexible.js

@ -0,0 +1,118 @@
;(function(win, lib) {
var doc = win.document;
var docEl = doc.documentElement;
var metaEl = doc.querySelector('meta[name="viewport"]');
var flexibleEl = doc.querySelector('meta[name="flexible"]');
var dpr = 0;
var scale = 0;
var tid;
var flexible = lib.flexible || (lib.flexible = {});
if (metaEl) {
console.warn('将根据已有的meta标签来设置缩放比例');
var match = metaEl.getAttribute('content').match(/initial\-scale=([\d\.]+)/);
if (match) {
scale = parseFloat(match[1]);
dpr = parseInt(1 / scale);
}
} else if (flexibleEl) {
var content = flexibleEl.getAttribute('content');
if (content) {
var initialDpr = content.match(/initial\-dpr=([\d\.]+)/);
var maximumDpr = content.match(/maximum\-dpr=([\d\.]+)/);
if (initialDpr) {
dpr = parseFloat(initialDpr[1]);
scale = parseFloat((1 / dpr).toFixed(2));
}
if (maximumDpr) {
dpr = parseFloat(maximumDpr[1]);
scale = parseFloat((1 / dpr).toFixed(2));
}
}
}
if (!dpr && !scale) {
var isAndroid = win.navigator.appVersion.match(/android/gi);
var isIPhone = win.navigator.appVersion.match(/iphone/gi);
var devicePixelRatio = win.devicePixelRatio;
if (isIPhone) {
// iOS下,对于2和3的屏,用2倍的方案,其余的用1倍方案
if (devicePixelRatio >= 3 && (!dpr || dpr >= 3)) {
dpr = 3;
} else if (devicePixelRatio >= 2 && (!dpr || dpr >= 2)){
dpr = 2;
} else {
dpr = 1;
}
} else {
// 其他设备下,仍旧使用1倍的方案
dpr = 1;
}
scale = 1 / dpr;
}
docEl.setAttribute('data-dpr', dpr);
if (!metaEl) {
metaEl = doc.createElement('meta');
metaEl.setAttribute('name', 'viewport');
metaEl.setAttribute('content', 'initial-scale=' + scale + ', maximum-scale=' + scale + ', minimum-scale=' + scale + ', user-scalable=no');
if (docEl.firstElementChild) {
docEl.firstElementChild.appendChild(metaEl);
} else {
var wrap = doc.createElement('div');
wrap.appendChild(metaEl);
doc.write(wrap.innerHTML);
}
}
function refreshRem(){
var width = docEl.getBoundingClientRect().width;
if (width / dpr > 540) {
width = 540 * dpr;
}
var rem = width / 10;
docEl.style.fontSize = rem + 'px';
flexible.rem = win.rem = rem;
}
win.addEventListener('resize', function() {
clearTimeout(tid);
tid = setTimeout(refreshRem, 300);
}, false);
win.addEventListener('pageshow', function(e) {
if (e.persisted) {
clearTimeout(tid);
tid = setTimeout(refreshRem, 300);
}
}, false);
if (doc.readyState === 'complete') {
doc.body.style.fontSize = 12 * dpr + 'px';
} else {
doc.addEventListener('DOMContentLoaded', function(e) {
doc.body.style.fontSize = 12 * dpr + 'px';
}, false);
}
refreshRem();
flexible.dpr = win.dpr = dpr;
flexible.refreshRem = refreshRem;
flexible.rem2px = function(d) {
var val = parseFloat(d) * this.rem;
if (typeof d === 'string' && d.match(/rem$/)) {
val += 'px';
}
return val;
}
flexible.px2rem = function(d) {
var val = parseFloat(d) / this.rem;
if (typeof d === 'string' && d.match(/px$/)) {
val += 'rem';
}
return val;
}
})(window, window['lib'] || (window['lib'] = {}));

BIN
plugins/flexible.js.zip

Binary file not shown.
Loading…
Cancel
Save