Commit 0247fd5c692292439795fae5c67f481ea01c4afc

Authored by YunaiV
2 parents 87989440 b4cde69d

Merge remote-tracking branch 'origin/feature/1.8.0-uniapp' into feature/1.8.0-uniapp

yudao-ui-app/components/yd-text-price/yd-text-price.vue
1 <template> 1 <template>
2 <view> 2 <view>
3 - <text v-for="(item, index) in textArray" :key="index" :style="{ 'font-size': (index === 1 ? integerSize : size) + 'px', 'color': color }"> 3 + <text v-for="(item, index) in textArray" :key="index" :style="{ fontSize: (index === 1 ? integerSize : size) + 'px', color, textDecoration }">
4 {{ item }} 4 {{ item }}
5 </text> 5 </text>
6 </view> 6 </view>
@@ -8,15 +8,20 @@ @@ -8,15 +8,20 @@
8 8
9 <script> 9 <script>
10 /** 10 /**
11 - * 此组件简单的显示特定样式的(人名币)价格数字 11 + * 此组件简单的显示(驼峰式)的价格
12 */ 12 */
13 export default { 13 export default {
14 name: 'yd-text-price', 14 name: 'yd-text-price',
15 components: {}, 15 components: {},
16 props: { 16 props: {
  17 + //货币符号
  18 + symbol: {
  19 + type: String,
  20 + default: '¥'
  21 + },
17 price: { 22 price: {
18 type: [String, Number], 23 type: [String, Number],
19 - default: '0.00' 24 + default: ''
20 }, 25 },
21 color: { 26 color: {
22 type: String, 27 type: String,
@@ -30,14 +35,28 @@ export default { @@ -30,14 +35,28 @@ export default {
30 //整形部分字体大小可单独定义 35 //整形部分字体大小可单独定义
31 intSize: { 36 intSize: {
32 type: [String, Number], 37 type: [String, Number],
33 - default: 15 38 + default: ''
  39 + },
  40 + //文字装饰,下划线,中划线等
  41 + decoration: {
  42 + type: String,
  43 + default: 'none'
  44 + }
  45 + },
  46 + data() {
  47 + return {
  48 + textDecoration: this.decoration
34 } 49 }
35 }, 50 },
36 computed: { 51 computed: {
37 textArray() { 52 textArray() {
38 - let array = ['¥'] 53 + let array = []
  54 + if (this.price === '' || this.price === undefined) {
  55 + return []
  56 + }
  57 + array.push(this.symbol)
39 if (!/^\d+(\.\d+)?$/.test(this.price)) { 58 if (!/^\d+(\.\d+)?$/.test(this.price)) {
40 - console.error('组件<custom-text-price :text="???" 此处参数应为金额数字') 59 + console.error('组件<yd-text-price :text="???" 此处参数应为金额数字')
41 } else { 60 } else {
42 let arr = parseFloat(this.price).toFixed(2).split('.') 61 let arr = parseFloat(this.price).toFixed(2).split('.')
43 array.push(arr[0]) 62 array.push(arr[0])
yudao-ui-app/pages/index/index.vue
@@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
28 <!--商品展示栏--> 28 <!--商品展示栏-->
29 <yd-product-box :product-list="productList" :title="'每日上新'" show-type="normal"></yd-product-box> 29 <yd-product-box :product-list="productList" :title="'每日上新'" show-type="normal"></yd-product-box>
30 <yd-product-box :product-list="productList" :title="'热卖商品'" show-type="half"></yd-product-box> 30 <yd-product-box :product-list="productList" :title="'热卖商品'" show-type="half"></yd-product-box>
31 - <yd-product-more :product-list="productList" more-status="moreStatus"></yd-product-more> 31 + <yd-product-more :product-list="productList" :more-status="moreStatus"></yd-product-more>
32 32
33 <u-gap height="5px"></u-gap> 33 <u-gap height="5px"></u-gap>
34 </view> 34 </view>
yudao-ui-app/store/getters.js 0 → 100644
  1 +const getters = {
  2 + accessToken: state => state.user.accessToken,
  3 + userInfo: state => state.user.userInfo,
  4 + hasLogin: state => !!state.user.accessToken
  5 +}
  6 +export default getters
yudao-ui-app/store/index.js
1 import Vue from 'vue' 1 import Vue from 'vue'
2 import Vuex from 'vuex' 2 import Vuex from 'vuex'
3 -import { logout } from '@/api/auth'  
4 -import { getUserInfo } from '@/api/user'  
5 -import { passwordLogin, smsLogin, weixinMiniAppLogin } from '@/api/auth'  
6 -  
7 -const AccessTokenKey = 'ACCESS_TOKEN'  
8 -const RefreshTokenKey = 'REFRESH_TOKEN' 3 +import user from './mudules/user'
  4 +import getters from './getters'
9 5
10 Vue.use(Vuex) // vue的插件机制 6 Vue.use(Vuex) // vue的插件机制
11 7
12 // Vuex.Store 构造器选项 8 // Vuex.Store 构造器选项
13 const store = new Vuex.Store({ 9 const store = new Vuex.Store({
14 - state: {  
15 - accessToken: uni.getStorageSync(AccessTokenKey), // 访问令牌  
16 - refreshToken: uni.getStorageSync(RefreshTokenKey), // 刷新令牌  
17 - userInfo: {}  
18 - },  
19 - getters: {  
20 - accessToken: state => state.accessToken,  
21 - refreshToken: state => state.refreshToken,  
22 - userInfo: state => state.userInfo,  
23 - hasLogin: state => !!state.accessToken 10 + modules: {
  11 + user
24 }, 12 },
25 - mutations: {  
26 - // 更新 state 的通用方法  
27 - SET_STATE_ATTR(state, param) {  
28 - if (param instanceof Array) {  
29 - for (let item of param) {  
30 - state[item.key] = item.val  
31 - }  
32 - } else {  
33 - state[param.key] = param.val  
34 - }  
35 - },  
36 - // 更新令牌  
37 - SET_TOKEN(state, data) {  
38 - // 设置令牌  
39 - const { accessToken, refreshToken } = data  
40 - state.accessToken = accessToken  
41 - state.refreshToken = refreshToken  
42 - uni.setStorageSync(AccessTokenKey, accessToken)  
43 - uni.setStorageSync(RefreshTokenKey, refreshToken)  
44 -  
45 - // 加载用户信息  
46 - this.dispatch('ObtainUserInfo')  
47 - },  
48 - // 更新用户信息  
49 - SET_USER_INFO(state, data) {  
50 - state.userInfo = data  
51 - },  
52 - // 清空令牌 和 用户信息  
53 - CLEAR_LOGIN_INFO(state) {  
54 - uni.removeStorageSync(AccessTokenKey)  
55 - uni.removeStorageSync(RefreshTokenKey)  
56 - state.accessToken = ''  
57 - state.refreshToken = ''  
58 - state.userInfo = {}  
59 - }  
60 - },  
61 - actions: {  
62 - //账号登录  
63 - Login({ state, commit }, { type, data }) {  
64 - if (type === 0) {  
65 - return passwordLogin(data).then(res => {  
66 - commit('SET_TOKEN', res.data)  
67 - })  
68 - } else if (type === 1) {  
69 - return smsLogin(data).then(res => {  
70 - commit('SET_TOKEN', res.data)  
71 - })  
72 - } else {  
73 - return weixinMiniAppLogin(data).then(res => {  
74 - commit('SET_TOKEN', res.data)  
75 - })  
76 - }  
77 - },  
78 - // 退出登录  
79 - async Logout({ state, commit }) {  
80 - commit('CLEAR_LOGIN_INFO')  
81 - await logout()  
82 - },  
83 - // 获得用户基本信息  
84 - async ObtainUserInfo({ state, commit }) {  
85 - const res = await getUserInfo()  
86 - commit('SET_USER_INFO', res.data)  
87 - }  
88 - } 13 + getters
89 }) 14 })
90 -  
91 export default store 15 export default store
yudao-ui-app/store/mudules/user.js 0 → 100644
  1 +import { getUserInfo } from '@/api/user'
  2 +import { passwordLogin, smsLogin, weixinMiniAppLogin, logout } from '@/api/auth'
  3 +
  4 +const AccessTokenKey = 'ACCESS_TOKEN'
  5 +const RefreshTokenKey = 'REFRESH_TOKEN'
  6 +
  7 +const user = {
  8 + state: {
  9 + accessToken: uni.getStorageSync(AccessTokenKey), // 访问令牌
  10 + refreshToken: uni.getStorageSync(RefreshTokenKey), // 刷新令牌
  11 + userInfo: {}
  12 + },
  13 + mutations: {
  14 + // 更新 state 的通用方法
  15 + SET_STATE_ATTR(state, param) {
  16 + if (param instanceof Array) {
  17 + for (let item of param) {
  18 + state[item.key] = item.val
  19 + }
  20 + } else {
  21 + state[param.key] = param.val
  22 + }
  23 + },
  24 + // 更新令牌
  25 + SET_TOKEN(state, data) {
  26 + // 设置令牌
  27 + const { accessToken, refreshToken } = data
  28 + state.accessToken = accessToken
  29 + state.refreshToken = refreshToken
  30 + uni.setStorageSync(AccessTokenKey, accessToken)
  31 + uni.setStorageSync(RefreshTokenKey, refreshToken)
  32 +
  33 + // 加载用户信息
  34 + this.dispatch('ObtainUserInfo')
  35 + },
  36 + // 更新用户信息
  37 + SET_USER_INFO(state, data) {
  38 + state.userInfo = data
  39 + },
  40 + // 清空令牌 和 用户信息
  41 + CLEAR_LOGIN_INFO(state) {
  42 + uni.removeStorageSync(AccessTokenKey)
  43 + uni.removeStorageSync(RefreshTokenKey)
  44 + state.accessToken = ''
  45 + state.refreshToken = ''
  46 + state.userInfo = {}
  47 + }
  48 + },
  49 + actions: {
  50 + //账号登录
  51 + Login({ state, commit }, { type, data }) {
  52 + if (type === 0) {
  53 + return passwordLogin(data)
  54 + .then(res => {
  55 + commit('SET_TOKEN', res.data)
  56 + return Promise.resolve(res)
  57 + })
  58 + .catch(err => {
  59 + return Promise.reject(err)
  60 + })
  61 + } else if (type === 1) {
  62 + return smsLogin(data)
  63 + .then(res => {
  64 + commit('SET_TOKEN', res.data)
  65 + return Promise.resolve(res)
  66 + })
  67 + .catch(err => {
  68 + return Promise.reject(err)
  69 + })
  70 + } else {
  71 + return weixinMiniAppLogin(data)
  72 + .then(res => {
  73 + commit('SET_TOKEN', res.data)
  74 + return Promise.resolve(res)
  75 + })
  76 + .catch(err => {
  77 + return Promise.reject(err)
  78 + })
  79 + }
  80 + },
  81 + // 退出登录
  82 + Logout({ state, commit }) {
  83 + return logout()
  84 + .then(res => {
  85 + return Promise.resolve(res)
  86 + })
  87 + .catch(err => {
  88 + return Promise.reject(err)
  89 + })
  90 + .finally(() => {
  91 + commit('CLEAR_LOGIN_INFO')
  92 + })
  93 + },
  94 + // 获得用户基本信息
  95 + async ObtainUserInfo({ state, commit }) {
  96 + const res = await getUserInfo()
  97 + commit('SET_USER_INFO', res.data)
  98 + }
  99 + }
  100 +}
  101 +export default user