Commit 36c5a016 authored by sunguoshu's avatar sunguoshu

过滤器

parent 1fbdf1b1
......@@ -8,7 +8,7 @@ module.exports = defineConfig({
dts: 'typings/apis',
printer: {
axiosImport: 'import axios from \'@/utils/remote\';',
prettier: fs.readJsonSync(path.resolve(__dirname, '.prettierrc.json')),
prettier: fs.readJsonSync(path.resolve(__dirname, '.prettierrc')),
responseTypeName: 'Promise',
},
openAPIs: [
......
......@@ -4,6 +4,7 @@
<router-view />
<TheLock v-if="configStore.isLock" />
<TheMagnifierDialogVue />
<TradeModal />
</div>
</a-config-provider>
</template>
......@@ -12,6 +13,7 @@
import zhCN from 'ant-design-vue/lib/locale/zh_CN'
import TheLock from '@/components/TheLock'
import TheMagnifierDialogVue from '@/components/Magnifier/magnifierDialog.vue'
import TradeModal from '@/components/Modal/Modal.vue'
import { useConfigStore } from '@/store/modules'
const configStore = useConfigStore()
......
/**
* 金额大写过滤器
* -------------------------
* coconear 2019/07/10
*
* 使用方法:
* {{111.02|chinesecCash}}
*/
export default function (input) {
let newInput
if (input === undefined || input === null || input === '' || !/^[\-]?\d{0,21}(\.\d{0,3})?$/.test(input)) {
return input;
}
if(/[\-]\d{0,21}(\.\d{0,3})?$/.test(input)){
newInput = input.replace(/-/,"");
}else{
newInput = input;
}
newInput = newInput.replace(/^0+$/, "0").replace(/^0+([1-9].*)/, "$1");
const CN1 = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
const CN2 = ['元', '万', '亿','兆','京','垓'];
const CN3 = ['', '拾', '佰', '仟'];
const CN4 = ['角', '分', '厘'];
newInput = newInput + "";
const arr = newInput.split(".");
let int = arr[0], dot = arr[1];
let intArr = int.split("");
let counter = 0;
for (let i = intArr.length - 1; i >= 0; i--) {
intArr[i] = CN1[intArr[i]] + CN3[counter % 4];
if (counter % 4 == 0) {
intArr[i] += CN2[counter / 4];
}
counter++;
}
int = intArr.join("").replace(/(零仟|零佰|零拾)/g, "零").replace(/零+/g, "零").replace(/零(元|万|亿|兆|京|垓)/g, "$1").replace(/亿万/, "亿").replace(/兆亿/,"兆").replace(/京兆/,"京").replace(/垓京/,"垓");
if (int === '元') {
int = '零元';
}
if (!dot || /^0+$/.test(dot)) {
if(/^[\-]\d{0,21}(\.\d{0,3})?$/.test(input)){
let value = input.length==1?"负":"负"+int+"整"
return value;
}else{
return int + "整";
}
} else {
dot = dot.split("").map(function (item, index) {
return CN1[item] + CN4[index];
}).join("");
dot = dot.replace(/(零角|零分|零厘)/g, "零").replace(/零+/g, "零").replace(/零$/, "");
if(/^[\-]\d{0,21}(\.\d{0,3})?$/.test(input)){
return "负" + int + dot;
}else{
return int + dot;
}
}
};
/**
* 日期格式过滤器
* -------------------------
* yelloxing 2019/04/16
*
* 使用方法:
* {{XXX|date('XXX')}}
*/
export default function (input, split) {
input = input + "";
split = split || "-";
if (input && /\d{8}/.test(input))
input = input.replace(/(\d{4})(\d{2})(\d{2})/, '$1' + split + '$2' + split + '$3');
return input;
};
/**
* 日期时间格式过滤器
* -------------------------
* coconear 2019/04/28
*
* 使用方法:
* {{XXX|dateTime('yyyy-MM-dd hh:mm:ss')}}
*/
export default function (input, mode) {
input = input + "";
mode = mode + "";
if (input && /\d{14}/.test(input)) {
let pattern = /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/.exec(input);
input = mode.replace(/yyyy/i, pattern[1]).replace(/MM/, pattern[2]).replace(/dd/i, pattern[3]).replace(/hh/i, pattern[4]).replace(/mm/, pattern[5]).replace(/ss/i, pattern[6]);
} else if (input && /\d{8}/.test(input)) {
let pattern = /^(\d{4})(\d{2})(\d{2})$/.exec(input);
input = mode.replace(/yyyy/i, pattern[1]).replace(/MM/, pattern[2]).replace(/dd/i, pattern[3]);
}
return input;
};
import Vue from 'vue'
import date from './date'
import dateTime from './dateTime'
import number from './number'
import time from './time'
import timeTodate from './timeTodate'
import chinesecCash from './chinesecCash'
import money from './money'
Vue.filter('date', date)
Vue.filter('dateTime', dateTime)
Vue.filter('number', number)
Vue.filter('time', time)
Vue.filter('timeTodate', timeTodate)
Vue.filter('chinesecCash', chinesecCash)
Vue.filter('money', money)
/**
* 金额格式化
* -------------------------
* coconear 2019/04/28
*
* 使用方法:
* {{XXX|money('XXX')}}
*/
/*
* formatMoney(s,type)
* 功能:金额按千位逗号分割
* 参数:s,需要格式化的金额数值.
* 参数:type,判断格式化后的金额是否需要小数位.
* 返回:返回格式化后的数值字符串.
*/
function formatMoney(s) {
if (/[^0-9\.]/.test(s))
return s;
if (s == null || s == "")
return s;
s = s.toString().replace(/^(\d*)$/, "$1.");
s = (s + "00").replace(/(\d*\.\d\d)\d*/, "$1");
s = s.replace(".", ",");
var re = /(\d)(\d{3},)/;
while (re.test(s))
s = s.replace(re, "$1,$2");
s = s.replace(/,(\d\d)$/, ".$1");
return s;
}
export default function (money) {
return formatMoney(money);
};
\ No newline at end of file
/**
* 数字过滤器
* -------------------------
* coconear 2019/04/27
*
* 使用方法:
* {{222.222|number(2)}}
*/
/**
* dot 小数位数
*/
export default function (input, dot) {
input = input + "";
if (!/^\d+(\.\d+)?$/.test(input)) {
return input;
}
dot = +(dot || 0);
let arr = input.indexOf(".")>-1?input.split("."):[input, "0"];
if (arr[1].length < dot) {
while (arr[1].length < dot) {
arr[1] += "0"
}
}else{
arr[1] = arr[1].substring(0,dot)
}
let number = arr[0] || '0';
let float = arr[1];
number = number.split("").reverse().join("").replace(/(\d{3})/g, "$1,").split("").reverse().join("").replace(/^,/, "");
return dot ? `${number}.${float.slice(0, dot)}` : `${number}`;
};
/**
* 时间格式过滤器
* -------------------------
* coconear 2019/04/28
*
* 使用方法:
* {{XXX|time('XXX')}}
*/
export default function (input, split) {
input = input + "";
split = split || ":";
if (input && /\d{6}/.test(input))
input = input.replace(/(\d{2})(\d{2})(\d{2})/, '$1' + split + '$2' + split + '$3');
return input;
};
/**
* 将时间戳转化为日期时间格式
* containhms:是否包含小时,分钟,秒
*/
export default function(timestamp,containhms=true) {
if(timestamp==''){
return;
}
var date = new Date(parseInt(timestamp));
var Y = date.getFullYear();
var M =(date.getMonth() + 1 < 10? "0" + (date.getMonth() + 1) : date.getMonth() + 1);
var D = date.getDate();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
if(containhms){
return Y + "-" + M + "-" + D + " " + h + ":" + m + ":" + s;
}else{
return Y + "-" + M + "-" + D
}
}
......@@ -13,6 +13,7 @@ import App from './App.vue'
import './directives'
import './themes/default.less'
import { createWaterMark } from './utils/waterMark'
import lodash from 'lodash'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
......@@ -28,6 +29,8 @@ import { VITE_APP_NAME } from '@/enums/env'
dayjs.locale('zh-cn')
const isLogin = location.hash.startsWith('#/login')
import './filter'
// ********** 组件 **********
Vue.use(Antd)
Vue.use(VXETable)
......@@ -40,6 +43,7 @@ Vue.prototype.$bus = bus // 事件总线
Vue.prototype.$moment = moment
Vue.prototype.$remote = post
Vue.prototype.$api = api
Vue.prototype.$lodash = lodash
Vue.prototype.$openTradeModal = (code: string, params: any, cb = () => {}) => {
bus.$emit('openTradeModal', code, params, cb)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment