|
|
@@ -1,14 +1,13 @@
|
|
|
|
|
|
const NULL_ARR = ['空', '没', '无', '-', '—', 'null', '#N/A']
|
|
|
|
|
|
-// 立即购买或加入购物车
|
|
|
/*
|
|
|
* isBuy: 是否是立即购买
|
|
|
* event: 触发事件
|
|
|
* $this: 当前对象
|
|
|
* item: 操作对象
|
|
|
* */
|
|
|
-const _buyNow = function (isBuy, event, $this, item) {
|
|
|
+const _buyOrCar = function (isBuy, event, $this, item) {
|
|
|
if (event) event.stopPropagation()
|
|
|
if (!$this.$store.state.option.user.logged) {
|
|
|
$this.$http.get('/login/page', {params: {returnUrl: window.location.href}}).then(response => {
|
|
|
@@ -96,7 +95,6 @@ const _buyNow = function (isBuy, event, $this, item) {
|
|
|
// window.location.href = 'user#/order/pay/' + $this.enidfilter($this.buy_info.orderid)
|
|
|
}
|
|
|
|
|
|
-// 订单号转换
|
|
|
const _enidfilter = (str) => {
|
|
|
if (str) {
|
|
|
let encryptStr = '' // 最终返回的加密后的字符串
|
|
|
@@ -165,7 +163,9 @@ const _enidfilter = (str) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 获取字符串字符长度
|
|
|
+/*
|
|
|
+* @str 字符串
|
|
|
+* */
|
|
|
const _getRealLen = function (str) {
|
|
|
let len = 0
|
|
|
for (let i = 0; i < str.length; i++) {
|
|
|
@@ -178,8 +178,10 @@ const _getRealLen = function (str) {
|
|
|
return len
|
|
|
}
|
|
|
|
|
|
-export const enidfilter = _enidfilter
|
|
|
-
|
|
|
+/*
|
|
|
+* @str 字符串
|
|
|
+* @length 需要剪切的字符长度
|
|
|
+* */
|
|
|
const _cutOutString = (str, length) => {
|
|
|
for (let i = 1; i <= str.length; i++) {
|
|
|
if (_getRealLen(str.substr(0, i)) > length) {
|
|
|
@@ -190,14 +192,7 @@ const _cutOutString = (str, length) => {
|
|
|
return str
|
|
|
}
|
|
|
|
|
|
-// 获取字符串字符长度
|
|
|
-export const getRealLen = _getRealLen
|
|
|
-
|
|
|
-// 根据字符长度剪切字符
|
|
|
-export const cutOutString = _cutOutString
|
|
|
-
|
|
|
-// 根据字符长度剪切字符
|
|
|
-export const spliceStr = (str, length) => {
|
|
|
+const _spliceStr = (str, length) => {
|
|
|
for (let i = 1; i <= str.length; i++) {
|
|
|
if (_getRealLen(str.substr(0, i)) > length) {
|
|
|
str = str.substr(0, i - 1) + '...'
|
|
|
@@ -207,8 +202,12 @@ export const spliceStr = (str, length) => {
|
|
|
return str
|
|
|
}
|
|
|
|
|
|
-// 格式化日期,返回字符串
|
|
|
-export const formatDate = (date, fmt) => {
|
|
|
+/*
|
|
|
+* @date 日期,既可以是Date格式,也可是字符串格式
|
|
|
+* @fmt 需要转换的格式,如 'yyyy-MM-dd hh:mm:ss'
|
|
|
+* return 转换后的字符串格式的日期
|
|
|
+* */
|
|
|
+const _formatDate = (date, fmt) => {
|
|
|
if (!date) {
|
|
|
return null
|
|
|
}
|
|
|
@@ -235,8 +234,10 @@ export const formatDate = (date, fmt) => {
|
|
|
return fmt
|
|
|
}
|
|
|
|
|
|
-// 检查空字符串或规定状态下空字符
|
|
|
-export const checkNullStr = (str) => {
|
|
|
+/*
|
|
|
+* @str 传入的字符串
|
|
|
+* */
|
|
|
+const _checkNullStr = (str) => {
|
|
|
// NULL_ARR.map(s => {
|
|
|
// if (str === s) {
|
|
|
// return false
|
|
|
@@ -250,8 +251,11 @@ export const checkNullStr = (str) => {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-// 联系卖家
|
|
|
-export const goLinkUser = ($this, enuu) => {
|
|
|
+/*
|
|
|
+* @$this 当前上下文
|
|
|
+* @enuu 企业uu
|
|
|
+* */
|
|
|
+const _goLinkUser = ($this, enuu) => {
|
|
|
if ($this.user.logged) {
|
|
|
// $this.$http.get('/basic/enterprise/' + $this.storeInfo.enUU + '/info').then(response => {
|
|
|
// if (response.data.enTel) {
|
|
|
@@ -283,38 +287,46 @@ export const goLinkUser = ($this, enuu) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 判断字符串开头
|
|
|
-export const startWith = function (str, s) {
|
|
|
+/*
|
|
|
+* @str: 传入的字符串
|
|
|
+* @s: 需要判断的字符串
|
|
|
+* */
|
|
|
+const _startWith = (str, s) => {
|
|
|
let reg = new RegExp('^' + s)
|
|
|
return reg.test(str)
|
|
|
}
|
|
|
|
|
|
-// 根据path文件名来判断文件是否是PDF文件
|
|
|
-export const judgeIsPdf = function (path) {
|
|
|
+/*
|
|
|
+* @path 文件路径地址
|
|
|
+* */
|
|
|
+const _judgeIsPdf = (path) => {
|
|
|
if (path) {
|
|
|
return path.slice(path.lastIndexOf('.')).toLowerCase() === '.pdf'
|
|
|
} else {
|
|
|
return false
|
|
|
}
|
|
|
}
|
|
|
-// 实现深拷贝
|
|
|
-export const deepCopy = function (target) {
|
|
|
+
|
|
|
+/*
|
|
|
+* @target 需要拷贝的对象
|
|
|
+* */
|
|
|
+const _deepCopy = (target) => {
|
|
|
if (typeof target !== 'object') return
|
|
|
// 判断目标类型,来创建返回值
|
|
|
var newObj = target instanceof Array ? [] : {}
|
|
|
for (var item in target) {
|
|
|
// 只复制元素自身的属性,不复制原型链上的
|
|
|
if (target.hasOwnProperty(item)) {
|
|
|
- newObj[item] = typeof target[item] === 'object' ? deepCopy(target[item]) : target[item]
|
|
|
+ newObj[item] = typeof target[item] === 'object' ? _deepCopy(target[item]) : target[item]
|
|
|
}
|
|
|
}
|
|
|
return newObj
|
|
|
}
|
|
|
|
|
|
-export function whichTransitionEvent() {
|
|
|
- var t
|
|
|
- var el = document.createElement('fakeelement')
|
|
|
- var transitions = {
|
|
|
+const _whichTransitionEvent = () => {
|
|
|
+ let t
|
|
|
+ let el = document.createElement('fakeelement')
|
|
|
+ let transitions = {
|
|
|
transition: 'transitionend',
|
|
|
OTransition: 'oTransitionEnd',
|
|
|
MozTransition: 'transitionend',
|
|
|
@@ -327,8 +339,38 @@ export function whichTransitionEvent() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export const buyOrCar = _buyNow
|
|
|
-
|
|
|
-export const filterStringEllipsis = (str, len) => {
|
|
|
+/*
|
|
|
+* @str 剪切的字符串
|
|
|
+* @len 长度设置
|
|
|
+* */
|
|
|
+const _filterStringEllipsis = (str, len) => {
|
|
|
return str ? _getRealLen(str) > len ? _cutOutString(str, len) + '...' : str : null
|
|
|
}
|
|
|
+
|
|
|
+export default {
|
|
|
+ // 获取字符串字符长度
|
|
|
+ getRealLen: _getRealLen,
|
|
|
+ // 根据字符长度剪切字符
|
|
|
+ cutOutString: _cutOutString,
|
|
|
+ // 订单号转换
|
|
|
+ enidfilter: _enidfilter,
|
|
|
+ // 根据字符长度剪切字符串
|
|
|
+ spliceStr: _spliceStr,
|
|
|
+ // 格式化日期,返回字符串
|
|
|
+ formatDate: _formatDate,
|
|
|
+ // 检查空字符串或规定状态下空字符
|
|
|
+ checkNullStr: _checkNullStr,
|
|
|
+ // 联系卖家
|
|
|
+ goLinkUser: _goLinkUser,
|
|
|
+ // 判断字符串开头
|
|
|
+ startWith: _startWith,
|
|
|
+ // 根据path文件名来判断文件是否是PDF文件
|
|
|
+ judgeIsPdf: _judgeIsPdf,
|
|
|
+ // 深拷贝对象
|
|
|
+ deepCopy: _deepCopy,
|
|
|
+ whichTransitionEvent: _whichTransitionEvent,
|
|
|
+ // 立即购买或加入购物车
|
|
|
+ buyOrCar: _buyOrCar,
|
|
|
+ // 截取字符长度并补充省略号
|
|
|
+ filterStringEllipsis: _filterStringEllipsis
|
|
|
+}
|