Browse Source

feat(theme): theme demo

refact
wally 4 years ago
parent
commit
91757586d3
  1. 32
      App.vue
  2. 1
      CHANGELOG.md
  3. 8
      common/styles/theme/default.scss
  4. 5
      common/styles/theme/index.scss
  5. 8
      common/styles/theme/test.scss
  6. 8
      components/Globals/Globals.vue
  7. 13
      components/Theme/Theme.vue
  8. 7
      components/TimeLine/component/Title.vue
  9. 7
      hooks/theme/useTheme.js
  10. 58
      pages.json
  11. 3
      pages/project/project.vue
  12. 9
      plugins/p-deliver/p-deliver.vue
  13. 4
      plugins/p-task-title/p-task-title.vue
  14. 70
      store/index.js

32
App.vue

@ -1,6 +1,21 @@
<script> <script>
// import { mapState } from 'vuex';
export default { export default {
// computed: {
// ...mapState(['theme']),
// },
// watch: {
// theme(newTheme) {
// console.log('newTheme: ', newTheme);
// if (!newTheme) return;
// this.loadTheme();
// },
// },
async onLaunch(options) { async onLaunch(options) {
// this.loadTheme();
console.log('onLaunch options: ', options); console.log('onLaunch options: ', options);
this.checkNetwork(); // this.checkNetwork(); //
this.getSystemInfo(); // this.getSystemInfo(); //
@ -16,6 +31,11 @@ export default {
}, },
methods: { methods: {
// loadTheme() {
// const path = this.theme.replace('-', '/');
// import(`./common/styles/${path}.scss`);
// },
async getToken() { async getToken() {
const { token } = this.$store.state.user; const { token } = this.$store.state.user;
const tokenIsAvailable = this.$store.getters['user/tokenIsAvailable']; const tokenIsAvailable = this.$store.getters['user/tokenIsAvailable'];
@ -63,18 +83,19 @@ export default {
} }
} }
if (this.$store.state.user.token && localToken) { // token if (this.$store.state.user.token && localToken) {
// token
this.$store.commit('user/setToken', localToken); this.$store.commit('user/setToken', localToken);
} }
if (this.$store.state.user.tokenExpiredTime && tokenExpiredTime) { // tokenExpiredTime if (this.$store.state.user.tokenExpiredTime && tokenExpiredTime) {
// tokenExpiredTime
this.$store.commit('user/setTokenExpiredTime', +tokenExpiredTime); this.$store.commit('user/setTokenExpiredTime', +tokenExpiredTime);
} }
resolve(); resolve();
} catch (error) { } catch (error) {
reject(error); reject(error);
} }
});
})
}, },
// store // store
@ -136,10 +157,11 @@ export default {
<style lang="scss"> <style lang="scss">
/*每个页面公共css */ /*每个页面公共css */
@import "@/uni_modules/vk-uview-ui/index.scss"; @import '@/uni_modules/vk-uview-ui/index.scss';
@import '@/common/styles/iconfont.scss'; @import '@/common/styles/iconfont.scss';
@import '@/common/styles/app.scss'; @import '@/common/styles/app.scss';
@import '@/common/styles/tailwind.scss'; @import '@/common/styles/tailwind.scss';
@import '@/common/styles/theme/index.scss';
page { page {
height: 100%; height: 100%;

1
CHANGELOG.md

@ -29,6 +29,7 @@
范围|描述|commitId 范围|描述|commitId
--|--|-- --|--|--
app.vue | 修复获取token报错的问题 | [9120d54](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/9120d54) app.vue | 修复获取token报错的问题 | [9120d54](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/9120d54)
createTask | 修复createTask v-model的问题 | [b20d3f0](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/b20d3f0)
- | 修复一些内容 | [3cdb1ce](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/3cdb1ce) - | 修复一些内容 | [3cdb1ce](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/3cdb1ce)

8
common/styles/theme/default.scss

@ -0,0 +1,8 @@
// 默认主题文件
.theme-default {
background-color: #333;
.u-card {
font-size: 24px !important;
color: #0f0;
}
}

5
common/styles/theme/index.scss

@ -0,0 +1,5 @@
// 整合所有主题
// 默认主题
@import './default.scss';
@import './test.scss';

8
common/styles/theme/test.scss

@ -0,0 +1,8 @@
// TODO: 测试用的scss主题样式
.theme-test {
background-color: #fff;
.u-card {
font-size: 24px !important;
background-color: #ff0 !important;
}
}

8
components/Globals/Globals.vue

@ -1,5 +1,5 @@
<template> <template>
<view class="m-2" > <theme class="m-2" >
<u-card <u-card
@click="openCard" @click="openCard"
:show-foot="false" :show-foot="false"
@ -7,6 +7,7 @@
:style="{ 'max-height': globalsHeight + 'px' }" :style="{ 'max-height': globalsHeight + 'px' }"
border-radius="25" border-radius="25"
margin="0" margin="0"
class="global-container"
> >
<template v-slot:body> <template v-slot:body>
<scroll-view :scrollY="true" :style="{ 'max-height': globalsHeight - 30 + 'px' }"> <scroll-view :scrollY="true" :style="{ 'max-height': globalsHeight - 30 + 'px' }">
@ -31,13 +32,16 @@
</view> </view>
</template> </template>
<!-- 任务名插件 -->
<p-task-title :task="item" v-else /> <p-task-title :task="item" v-else />
<!-- 交付物插件 -->
<p-deliver></p-deliver>
</view> </view>
</view> </view>
</scroll-view> </scroll-view>
</template> </template>
</u-card> </u-card>
</view> </theme>
</template> </template>
<script setup> <script setup>

13
components/Theme/Theme.vue

@ -0,0 +1,13 @@
<template>
<view :class="[theme]">
<slot></slot>
</view>
</template>
<script setup>
import { computed } from 'vue';
import { useStore } from 'vuex';
const store = useStore();
const theme = computed(() => store.state.theme);
</script>

7
components/TimeLine/component/Title.vue

@ -1,7 +0,0 @@
<!--
* @Author: aBin
* @email: binbin0314@126.com
* @Date: 2021-07-19 15:40:02
* @LastEditors: aBin
* @LastEditTime: 2021-07-19 15:40:03
-->

7
hooks/theme/useTheme.js

@ -0,0 +1,7 @@
import { computed } from 'vue';
import { useStore } from 'vuex';
export default function useTheme() {
const store = useStore();
const theme = computed(() => store.state.theme);
return theme;
}

58
pages.json

@ -1,30 +1,32 @@
{ {
"pages": [ //pageshttps://uniapp.dcloud.io/collocation/pages "pages": [
{ //pageshttps://uniapp.dcloud.io/collocation/pages
"path": "pages/index/index", {
"style": { "path": "pages/index/index",
"navigationBarText": "TALL" "style": {
} "navigationBarText": "TALL"
}, }
{ },
"path": "pages/project/project", {
"style": { "path": "pages/project/project",
"navigationStyle": "custom", "style": {
"navigationBarTextStyle": "white" "navigationStyle": "custom",
} "navigationBarTextStyle": "white"
} }
], }
"globalStyle": { ],
"navigationBarTextStyle": "black", "globalStyle": {
"navigationBarTitleText": "TALL", "navigationBarTextStyle": "black",
"navigationBarBackgroundColor": "#F8F8F8", "navigationBarTitleText": "TALL",
"backgroundColor": "#F8F8F8" "navigationBarBackgroundColor": "#F8F8F8",
}, "backgroundColor": "#F8F8F8"
"easycom": { },
"autoscan": true, "easycom": {
"custom": { "autoscan": true,
"^u-(.*)": "uview-ui/components/u-$1/u-$1.vue", "custom": {
"^p-(.*)": "@/plugins/p-$1/p-$1.vue" "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue",
} "^p-(.*)": "@/plugins/p-$1/p-$1.vue",
} "theme": "@/components/Theme/Theme.vue"
}
}
} }

3
pages/project/project.vue

@ -13,6 +13,9 @@
<!-- 定期任务面板 --> <!-- 定期任务面板 -->
<!-- <TimeLine @getTasks="getTasks" class="flex-1 overflow-hidden" ref="timeLine" /> --> <!-- <TimeLine @getTasks="getTasks" class="flex-1 overflow-hidden" ref="timeLine" /> -->
<TimeLine class="flex-1 overflow-hidden" ref="timeLine" /> <TimeLine class="flex-1 overflow-hidden" ref="timeLine" />
<!-- TODO: DEBUG: -->
<u-button @click="$store.commit('setTheme', 'theme-test')">测试切换主题</u-button>
</view> </view>
</view> </view>
</template> </template>

9
plugins/p-deliver/p-deliver.vue

@ -0,0 +1,9 @@
<template>
<view class="deliver-container">p-deliver</view>
</template>
<script setup>
</script>
<style lang="scss"></style>

4
plugins/p-task-title/p-task-title.vue

@ -1,6 +1,8 @@
<template> <template>
<!-- 任务名插件 --> <!-- 任务名插件 -->
<view>{{ task.name }}</view> <theme>
<view>{{ task.name }}</view>
</theme>
</template> </template>
<script setup> <script setup>

70
store/index.js

@ -1,48 +1,58 @@
import { createStore } from 'vuex'; import { createStore } from 'vuex';
import user from './user/index.js';
import socket from './socket/index.js';
import project from './project/index.js'; import project from './project/index.js';
import role from './role/index.js'; import role from './role/index.js';
import socket from './socket/index.js';
import task from './task/index.js'; import task from './task/index.js';
import user from './user/index.js';
// 不属于具体模块的 应用级的 store内容 // 不属于具体模块的 应用级的 store内容
const state = { const state = {
networkConnected: true, // 网络是否连接 theme: 'theme-default',
forceUseStorage: true, // 强制启用storage networkConnected: true, // 网络是否连接
systemInfo: null, // 系统设备信息 forceUseStorage: true, // 强制启用storage
systemInfo: null, // 系统设备信息
}; };
const getters = { const getters = {
// 是否启用本地存储 // 是否启用本地存储
// 设置了强制启用本地存储 或者 没有网络连接的时候 // 设置了强制启用本地存储 或者 没有网络连接的时候
useStorage({ networkConnected, forceUseStorage }) { useStorage({ networkConnected, forceUseStorage }) {
return forceUseStorage || !networkConnected; return forceUseStorage || !networkConnected;
}, },
}; };
const mutations = { const mutations = {
/** /**
* 设置网络是否连接的变量 * 设置网络是否连接的变量
* @param {*} state * @param {*} state
* @param {boolean} networkConnected * @param {boolean} networkConnected
*/ */
setNetworkConnected(state, networkConnected) { setNetworkConnected(state, networkConnected) {
state.networkConnected = networkConnected; state.networkConnected = networkConnected;
}, },
/**
* 设置系统信息的数据
* @param {object} state
* @param {object | null} data 获取到的数据
*/
setSystemInfo(state, data) {
state.systemInfo = data;
},
/** /**
* 设置系统信息的数据 * 设置主题
* @param {object} state * @param {object} state
* @param {object | null} data 获取到的数据 * @param {string} theme 主题名称 默认theme-default
*/ */
setSystemInfo(state, data) { setTheme(state, theme) {
state.systemInfo = data; state.theme = theme || 'theme-default';
}, },
}; };
export default createStore({ export default createStore({
state, state,
getters, getters,
mutations, mutations,
modules: {user, socket, project, role, task} modules: { user, socket, project, role, task },
}); });

Loading…
Cancel
Save