w-vue-middle
Version:
统一公共服务组件
652 lines (646 loc) • 14.6 kB
JavaScript
/*
* @Author: Jason Liu
* @Date: 2022-12-07 16:16:22
* @Desc:
*/
import draggable from 'vuedraggable';
export default {
components: { draggable },
name: 'fieldAuxiliaries',
props: {
value: {
type: Array,
default: () => {
return [];
},
},
},
data() {
return {
tables: this.value,
showTables: [],
loading: false,
name: undefined,
funName: undefined,
functionList: [
{
name: 'CONCAT',
use: 'CONCAT(x,y)',
desc: $t('连接字符串X和Y'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'INSERT',
use: 'INSERT(x,y,len,z)',
desc: $t('从X中查找str,可以指定从start开始,也可以指定从n开始'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'LENGTH',
use: 'LENGTH(X)',
desc: $t('返回X的长度'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'LOWER',
use: 'LOWER(x)',
desc: $t('X转换成小写'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'UPPER',
use: 'UPPER(x)',
desc: $t('X转换成大写'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'LTRIM',
use: 'LTRIM(x)',
desc: $t('把X的左边截去trim_str字符串,缺省截去空格'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'RTRIM',
use: 'RTRIM(x)',
desc: $t('把X的右边截去trim_str字符串,缺省截去空格'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'TRIM',
use: 'TRIM(x)',
desc: $t('把X的两边截去trim_str字符串,缺省截去空格'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'REPLACE',
use: 'REPLACE(x,old,new)',
desc: $t('在X中查找old,并替换成new'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'SUBSTR',
use: 'SUBSTR(x,n,len)',
desc: $t('返回X的字串,从start处开始,截取length个字符,缺省length,默认到结尾'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'ABS',
use: 'ABS(x)',
desc: $t('X的绝对值'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'ACOS',
use: 'ACOS(x)',
desc: $t('X的反余弦'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'COS',
use: 'COS(x)',
desc: $t('余弦'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'CEIL',
use: 'CEIL(x)',
desc: $t('大于或等于X的最小值'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'FLOOR',
use: 'FLOOR(x)',
desc: $t('小于或等于X的最大值'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'LOG',
use: 'LOG(x,y)',
desc: $t('X为底Y的对数'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'MOD',
use: 'MOD(x,y)',
desc: $t('X除以Y的余数'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'ROUND',
use: 'ROUND(x[,y])',
desc: $t('X在第Y位四舍五入'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'SQRT',
use: 'SQRT(x)',
desc: $t('X的平方根'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'TRUNC',
use: 'TRUNC(x[,y])',
desc: $t('X在第Y位截断'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'AVG',
use: 'AVG(x)',
desc: $t('取平均值'),
isGroup: true,
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'SUM',
use: 'SUM(x)',
desc: $t('求和'),
isGroup: true,
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'MIN',
use: 'MIN(x)',
desc: $t('最小值'),
isGroup: true,
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'COUNT',
use: 'COUNT(x)',
desc: $t('数据统计'),
isGroup: true,
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'MAX',
use: 'MAX(x)',
desc: $t('最大值'),
isGroup: true,
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'NOW',
use: 'NOW()',
desc: $t('当前日期'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'DATE_FORMAT',
use: 'DATE_FORMAT(timestamp, string)',
desc: $t('日期转字符串'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'TO_DATE',
use: 'TO_DATE(string1, string2)',
desc: $t('字符串转日期'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'TIMESTAMPDIFF',
use: 'TIMESTAMPDIFF(timepointunit, timepoint1,timepoint2)',
desc: $t('字符串转日期'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ')',
},
],
},
{
name: 'COALESCE',
use: 'COALESCE(expression,value1,value2……,valuen)',
desc: $t('进行空值处理'),
options: [
{
type: 'symbol',
data: '(',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ',',
},
{
type: 'symbol',
data: ')',
},
],
},
],
tablekey: 0,
};
},
created() {
this.searchTableList();
},
methods: {
/**
* @Author: Jason Liu
* @description: 克隆函数事件
*/
cloneFunEntry(row) {
return {
id: `${new Date().getTime()}`,
type: 'fun', //节点类型 字段:column 操作符:symbol 数值:value 函数:fun
name: row.name,
use: row.use,
desc: row.desc,
isGroup: row.isGroup,
options: row.options.map((item, i) => {
return {
id: `${new Date().getTime()}${i}`,
type: item.type, //节点类型 字段:column 操作符:symbol 数值:value 函数:fun
data: item.data,
options: undefined,
};
}),
};
},
/**
* @Author: Jason Liu
* @description: 克隆字段事件
*/
cloneColumnsEntry(row) {
return {
id: `${new Date().getTime()}`,
type: 'column', //节点类型 字段:column 操作符:symbol 数值:value 函数:fun
tableId: row.parentId, //表格ID
tableName: row.tableName,
code: row.code, //编码
name: row.name, //名称
columnName: row.columnName, //字段名称,
position: row.position, //位置
};
},
/**
* @Author: Jason Liu
* @description: 查询表格列信息
*/
searchTableList() {
if (this.name) {
this.showTables = this.tables.map((table) => {
return {
...table,
columns: table.columns.filter((row) => {
return row.name.toLocaleLowerCase().indexOf(this.name.toLocaleLowerCase()) > -1;
}),
};
});
} else {
this.showTables = this.tables;
}
this.tablekey++;
},
/**
* @Author: Jason Liu
* @description: 查询函数信息
*/
searchFunList() {
const xTable = this.$refs.functionList;
const column = xTable.getColumnByField('name');
// 修改第二个选项为勾选状态
const option = column.filters[0];
option.data = this.funName;
option.checked = !!this.funName;
// 修改条件之后,需要手动调用 updateData 处理表格数据
xTable.updateData();
},
/**
* @Author: Jason Liu
* @description: 查询幻术
*/
filterFunName({ option, row }) {
return row.name.toLocaleLowerCase().indexOf(option.data.toLocaleLowerCase()) > -1;
},
},
watch: {
value(val) {
this.tables = val;
this.searchTableList();
},
},
};