Skip to content

Commit

Permalink
Add multilingual.
Browse files Browse the repository at this point in the history
  • Loading branch information
Geek-James committed Jan 9, 2020
1 parent c84bc23 commit 0ebbdb8
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 129 deletions.
121 changes: 0 additions & 121 deletions src/config/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,127 +18,6 @@ export const removeLocalStore = (name) => {
if (!name) return;
return window.localStorage.removeItem(name);
}
/**
*
* @desc 判断是否为手机号
* @param {String|Number} str
* @return {Boolean}
*/
export const isPhoneNum = (str) => {
return /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/.test(str)
}

/**
*
* @desc 根据name读取cookie
* @param {String} name
* @return {String}
*/
export const getCookie = (name) => {
var arr = document.cookie.replace(/\s/g, "").split(';');
for (var i = 0; i < arr.length; i++) {
var tempArr = arr[i].split('=');
if (tempArr[0] == name) {
return decodeURIComponent(tempArr[1]);
}
}
return '';
}

/**
*
* @desc 设置Cookie
* @param {String} name
* @param {String} value
* @param {Number} days
*/
export const setCookie = (name, value, days) => {
var date = new Date();
date.setDate(date.getDate() + days);
document.cookie = name + '=' + value + ';expires=' + date;
}

/**
*
* @desc 根据name删除cookie
* @param {String} name
*/
export const removeCookie = (name) => {
// 设置已过期,系统会立刻删除cookie
setCookie(name, '1', -1);
}

/**
*
* @desc 获取浏览器类型和版本
* @return {String}
*/
export const getExplore = () => {
var sys = {},
ua = navigator.userAgent.toLowerCase(),
s;
(s = ua.match(/rv:([\d.]+)\) like gecko/)) ? sys.ie = s[1]:
(s = ua.match(/msie ([\d\.]+)/)) ? sys.ie = s[1] :
(s = ua.match(/edge\/([\d\.]+)/)) ? sys.edge = s[1] :
(s = ua.match(/firefox\/([\d\.]+)/)) ? sys.firefox = s[1] :
(s = ua.match(/(?:opera|opr).([\d\.]+)/)) ? sys.opera = s[1] :
(s = ua.match(/chrome\/([\d\.]+)/)) ? sys.chrome = s[1] :
(s = ua.match(/version\/([\d\.]+).*safari/)) ? sys.safari = s[1] : 0;
// 根据关系进行判断
if (sys.ie) return ('IE: ' + sys.ie)
if (sys.edge) return ('EDGE: ' + sys.edge)
if (sys.firefox) return ('Firefox: ' + sys.firefox)
if (sys.chrome) return ('Chrome: ' + sys.chrome)
if (sys.opera) return ('Opera: ' + sys.opera)
if (sys.safari) return ('Safari: ' + sys.safari)
return 'Unkonwn'
}

/**
*
* @desc 对象序列化
* @param {Object} obj
* @return {String}
*/
export const stringfyQueryString = (obj) => {
if (!obj) return '';
var pairs = [];

for (var key in obj) {
var value = obj[key];

if (value instanceof Array) {
for (var i = 0; i < value.length; ++i) {
pairs.push(encodeURIComponent(key + '[' + i + ']') + '=' + encodeURIComponent(value[i]));
}
continue;
}

pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));
}

return pairs.join('&');
}


/**
*
* @desc 判断是否为身份证号
* @param {String|Number} str
* @return {Boolean}
*/
export const isIdCard = (str) => {
return /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(str)
}

/**
*
* @desc 判断是否为邮箱地址
* @param {String} str
* @return {Boolean}
*/
let isEmail = (str) => {
return /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(str);
}
// 版本信息
export const _VERSION_ = "1.3.0";
2 changes: 1 addition & 1 deletion src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default {
mine: {
title: 'Mine',
phone: 'Tel',
login: 'Login immediately',
login: 'Login',
myOrder: 'My order',
allOrder: "View all orders",
myBill: 'My coupon',
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default {
servier: '联系客服',
servierTime: '客服时间 07:00-22:00',
feedback: '意见反馈',
switchLanguage: '语言切换',
switchLanguage: '语言',
chinese: '中文',
english: '英文',
version: '当前版本',
Expand Down
6 changes: 3 additions & 3 deletions src/views/home/components/header/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Motto: 求知若渴,虚心若愚
* @Github: https://github.com/Geek-James/ddBuy
* @掘金: https://juejin.im/user/5c4ebc72e51d4511dc7306ce
* @LastEditTime : 2020-01-06 15:37:30
* @LastEditTime : 2020-01-09 23:40:35
* @Description: 首页->顶部搜索栏
* @FilePath: /ddBuy/src/views/home/components/header/Header.vue
-->
Expand All @@ -21,7 +21,7 @@
<!-- 跳转到地图界面 -->
<router-link to="/dashboard/map"
tag="span"
class="address">{{$t(location)}}</router-link>
class="address">{{location || $t('home.chooseLocation')}}</router-link>
<svg-icon iconClass="up_real" />
</div>
<div class="searchWrapper"
Expand Down Expand Up @@ -50,7 +50,7 @@ export default {
data () {
return {
showBgColor: false,
location: getLocalStore('userLocation') || "home.chooseLocation"
location: getLocalStore('userLocation')
}
},
mounted () {
Expand Down
2 changes: 1 addition & 1 deletion src/views/home/components/nav/Nav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Motto: 求知若渴,虚心若愚
* @Github: https://github.com/Geek-James/ddBuy
* @掘金: https://juejin.im/user/5c4ebc72e51d4511dc7306ce
* @LastEditTime: 2019-11-07 09:16:39
* @LastEditTime : 2020-01-09 23:28:38
* @Description: 首页->Nav组件
* @FilePath: /ddBuy/src/views/home/components/nav/Nav.vue
-->
Expand Down
4 changes: 2 additions & 2 deletions src/views/home/components/tabbar/ProduceItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* @Motto: 求知若渴,虚心若愚
* @Github: https://github.com/Geek-James/ddBuy
* @掘金: https://juejin.im/user/5c4ebc72e51d4511dc7306ce
* @LastEditTime : 2019-12-24 13:14:04
* @LastEditTime : 2020-01-09 23:28:50
* @Description: 首页->产品列表
* @FilePath: /ddBuy/src/views/home/components/tabbar/ProduceItem.vue
-->
<template>
<div id="produceItem">
<div class="item"
v-for="(product,index) in product_lists"
:key="product.id"
:key="index"
@click.stop="goToGoodsDetail(product)">
<img v-lazy="product.small_image"
alt="">
Expand Down

0 comments on commit 0ebbdb8

Please sign in to comment.