This commit is contained in:
kuaifan 2022-01-05 20:19:27 +08:00
parent dde32fcaee
commit 90336e1edf
22 changed files with 487 additions and 748 deletions

View File

@ -189,7 +189,7 @@ export default {
ipcRenderer.send('windowHidden');
})
ipcRenderer.on('dispatch', (event, args) => {
if (!this.$store.state.method.isJson(args)) {
if (!$A.isJson(args)) {
return;
}
let {action, data} = args;

View File

@ -1,3 +1,6 @@
import './functions/common'
import './functions/web'
import Vue from 'vue'
import Vuex from 'vuex'
import App from './App.vue'
@ -7,9 +10,6 @@ import ViewUI from 'view-design-hi';
import Language from './language/index'
import store from './store/index'
import './functions/common'
import './functions/web'
Vue.use(Vuex);
Vue.use(ViewUI);
Vue.use(VueRouter);

View File

@ -103,7 +103,7 @@ export default {
},
methods: {
getReleases() {
let appdown = this.$store.state.method.getStorageJson("cacheAppdown");
let appdown = $A.getStorageJson("cacheAppdown");
if (appdown.time && appdown.time + 3600 > Math.round(new Date().getTime() / 1000)) {
this.chackReleases(appdown.data)
return;
@ -113,7 +113,7 @@ export default {
.get("https://api.github.com/repos/" + this.repoName + "/releases/latest")
.then(({status, data}) => {
if (status === 200) {
this.$store.state.method.setStorage("cacheAppdown", {
$A.setStorage("cacheAppdown", {
time: Math.round(new Date().getTime() / 1000),
data: data
});

View File

@ -108,7 +108,7 @@
},
data () {
return {
actionUrl: this.$store.state.method.apiUrl('system/imgupload'),
actionUrl: $A.apiUrl('system/imgupload'),
params: {
width: this.width,
height: this.height
@ -169,7 +169,7 @@
uploadHeaders() {
return {
fd: this.$store.state.method.getStorageString("userWsFd"),
fd: $A.getStorageString("userWsFd"),
token: this.userToken,
}
},

View File

@ -158,7 +158,7 @@
uploadIng: 0,
uploadFormat: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz', 'ai', 'avi', 'bmp', 'cdr', 'eps', 'mov', 'mp3', 'mp4', 'pr', 'psd', 'svg', 'tif'],
actionUrl: this.$store.state.method.apiUrl('system/fileupload'),
actionUrl: $A.apiUrl('system/fileupload'),
maxSize: 204800
};
},
@ -173,7 +173,7 @@
headers() {
return {
fd: this.$store.state.method.getStorageString("userWsFd"),
fd: $A.getStorageString("userWsFd"),
token: this.userToken,
}
},

View File

@ -100,7 +100,7 @@ export default {
return;
}
this.loadIng++;
$A.loadScript(this.$store.state.method.apiUrl("../office/web-apps/apps/api/documents/api.js"), (e) => {
$A.loadScript($A.apiUrl("../office/web-apps/apps/api/documents/api.js"), (e) => {
this.loadIng--;
if (e !== null) {
$A.modalAlert("组件加载失败!");
@ -168,10 +168,10 @@ export default {
config.editorConfig.mode = "view";
config.editorConfig.callbackUrl = null;
if (!config.editorConfig.user.id) {
let viewer = this.$store.state.method.getStorageInt("viewer")
let viewer = $A.getStorageInt("viewer")
if (!viewer) {
viewer = $A.randNum(1000, 99999);
this.$store.state.method.setStorage("viewer", viewer)
$A.setStorage("viewer", viewer)
}
config.editorConfig.user.id = "viewer_" + viewer;
config.editorConfig.user.name = "Viewer_" + viewer

View File

@ -138,7 +138,7 @@
uploadIng: 0,
uploadFormat: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz'],
actionUrl: this.$store.state.method.apiUrl('system/fileupload'),
actionUrl: $A.apiUrl('system/fileupload'),
maxSize: 10240
};
},
@ -162,7 +162,7 @@
headers() {
return {
fd: this.$store.state.method.getStorageString("userWsFd"),
fd: $A.getStorageString("userWsFd"),
token: this.userToken,
}
},

View File

@ -5,7 +5,7 @@
/**
* =============================================================================
* ************************** 基础函数类 **************************
* ******************************* 基础函数类 *******************************
* =============================================================================
*/
$.extend({
@ -27,6 +27,19 @@
return typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && typeof obj.length == "undefined";
},
/**
* 是否在数组里
* @param key
* @param array
* @returns {boolean|*}
*/
inArray(key, array) {
if (!this.isArray(array)) {
return false;
}
return array.includes(key);
},
/**
* 随机获取范围
* @param Min
@ -44,7 +57,7 @@
* @param array
* @returns {boolean}
*/
last: function (array) {
last(array) {
let str = false;
if (typeof array === 'object' && array.length > 0) {
str = array[array.length - 1];
@ -60,7 +73,7 @@
* @param lower
* @returns {boolean}
*/
strExists: function (string, find, lower = false) {
strExists(string, find, lower = false) {
string += "";
find += "";
if (lower !== true) {
@ -77,7 +90,7 @@
* @param lower
* @returns {boolean}
*/
leftExists: function (string, find, lower = false) {
leftExists(string, find, lower = false) {
string += "";
find += "";
if (lower !== true) {
@ -94,7 +107,7 @@
* @param lower
* @returns {string}
*/
leftDelete: function (string, find, lower = false) {
leftDelete(string, find, lower = false) {
string += "";
find += "";
if (this.leftExists(string, find, lower)) {
@ -110,7 +123,7 @@
* @param lower
* @returns {boolean}
*/
rightExists: function (string, find, lower = false) {
rightExists(string, find, lower = false) {
string += "";
find += "";
if (lower !== true) {
@ -127,7 +140,7 @@
* @param end
* @returns {*}
*/
getMiddle: function (string, start, end) {
getMiddle(string, start, end) {
string = string.toString();
if (this.ishave(start) && this.strExists(string, start)) {
string = string.substring(string.indexOf(start) + start.length);
@ -145,7 +158,7 @@
* @param end
* @returns {string}
*/
subString: function(string, start, end) {
subString(string, start, end) {
string += "";
if (!this.ishave(end)) {
end = string.length;
@ -158,7 +171,7 @@
* @param len
* @returns {string}
*/
randomString: function (len) {
randomString(len) {
len = len || 32;
let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678oOLl9gqVvUuI1';
let maxPos = $chars.length;
@ -174,7 +187,7 @@
* @param set
* @returns {boolean}
*/
ishave: function (set) {
ishave(set) {
return !!(set !== null && set !== "null" && set !== undefined && set !== "undefined" && set);
},
@ -184,7 +197,7 @@
* @param fixed
* @returns {number}
*/
runNum: function (str, fixed) {
runNum(str, fixed) {
let _s = Number(str);
if (_s + "" === "NaN") {
_s = 0;
@ -202,103 +215,13 @@
return _s;
},
/**
* 服务器地址
* @param str
* @returns {string}
*/
originUrl: function (str) {
if (str.substring(0, 2) === "//" ||
str.substring(0, 7) === "http://" ||
str.substring(0, 8) === "https://" ||
str.substring(0, 6) === "ftp://" ||
str.substring(0, 1) === "/") {
return str;
}
if (window.systemInformation && typeof window.systemInformation.origin === "string") {
str = window.systemInformation.origin + str;
} else {
str = window.location.origin + "/" + str;
}
while (str.indexOf("/../") !== -1) {
str = str.replace(/\/(((?!\/).)*)\/\.\.\//, "/")
}
return str
},
/**
* 新增&&获取缓存数据
* @param key
* @param value
* @returns {*}
*/
storage: function(key, value) {
let keyName = 'app';
switch (window.location.pathname) {
case "/admin":
keyName+= ":" + window.location.pathname.substr(1);
break;
}
if (typeof value === 'undefined') {
return this.loadFromlLocal('__::', key, '', '__' + keyName + '__');
}else{
this.savaToLocal('__::', key, value, '__' + keyName + '__');
}
},
/**
* 新增&&修改本地缓存
* @param {string} id 唯一id
* @param {string} key 标示
* @param value 新增&修改的值
* @param keyName 主键名称
*/
savaToLocal: function(id, key, value, keyName) {
try {
if (typeof keyName === 'undefined') keyName = '__seller__';
let seller = window.localStorage[keyName];
if (!seller) {
seller = {};
seller[id] = {};
} else {
seller = JSON.parse(seller);
if (!seller[id]) {
seller[id] = {};
}
}
seller[id][key] = value;
window.localStorage[keyName] = JSON.stringify(seller);
} catch(e) { }
},
/**
* 查询本地缓存
* @param {string} id 唯一id
* @param {string} key 标示
* @param def 如果查询不到显示的值
* @param keyName 主键名称
*/
loadFromlLocal: function(id, key, def, keyName) {
if (typeof keyName === 'undefined') keyName = '__seller__';
let seller = window.localStorage[keyName];
if (!seller) {
return def;
}
seller = JSON.parse(seller)[id];
if (!seller) {
return def;
}
let ret = seller[key];
return ret || def;
},
/**
* 返回10位数时间戳
* @param v
* @returns {number}
* @constructor
*/
Time: function (v) {
Time(v) {
let time
if (typeof v === "string" && this.strExists(v, "-")) {
v = v.replace(/-/g, '/');
@ -315,7 +238,7 @@
* @returns {Date}
* @constructor
*/
Date: function (v) {
Date(v) {
if (typeof v === "string" && this.strExists(v, "-")) {
v = v.replace(/-/g, '/');
}
@ -329,7 +252,7 @@
* @param after
* @returns {*}
*/
zeroFill: function(str, length, after) {
zeroFill(str, length, after) {
str+= "";
if (str.length >= length) {
return str;
@ -352,7 +275,7 @@
* @param v
* @returns {string}
*/
formatDate: function(format, v) {
formatDate(format, v) {
if (typeof format === 'undefined' || format === '') {
format = 'Y-m-d H:i:s';
}
@ -393,7 +316,7 @@
* @param e
* @returns {*}
*/
timeDiff: function(s, e) {
timeDiff(s, e) {
if (typeof e === 'undefined') {
e = $A.Time();
}
@ -422,7 +345,7 @@
* @param str
* @returns {boolean}
*/
isMobile: function(str) {
isMobile(str) {
return /^1([3456789])\d{9}$/.test(str);
},
@ -431,7 +354,7 @@
* @param phone
* @returns {boolean}
*/
isPhone: function (phone) {
isPhone(phone) {
return this.isMobile(phone);
},
@ -443,7 +366,7 @@
* @param lat2
* @returns {string|*}
*/
getDistance: function (lng1, lat1, lng2, lat2) {
getDistance(lng1, lat1, lng2, lat2) {
let DEF_PI = 3.14159265359; // PI
let DEF_2PI = 6.28318530712; // 2*PI
let DEF_PI180 = 0.01745329252; // PI/180.0
@ -716,14 +639,14 @@
});
return url;
}
var urlparts = url.split('?');
let urlparts = url.split('?');
if (urlparts.length >= 2) {
//参数名前缀
var prefix = encodeURIComponent(parameter) + '=';
var pars = urlparts[1].split(/[&;]/g);
let prefix = encodeURIComponent(parameter) + '=';
let pars = urlparts[1].split(/[&;]/g);
//循环查找匹配参数
for (var i = pars.length; i-- > 0;) {
for (let i = pars.length; i-- > 0;) {
if (pars[i].lastIndexOf(prefix, 0) !== -1) {
//存在则删除
pars.splice(i, 1);
@ -748,7 +671,7 @@
}
url+= "";
url+= url.indexOf("?") === -1 ? '?' : '';
for (var key in params) {
for (let key in params) {
if (!params.hasOwnProperty(key)) {
continue;
}
@ -859,58 +782,6 @@
document.body.scrollTop = document.body.scrollTop - 1;
},
autoDevwid(width) {
let _width = width || 640;
new function () {
let _self = this;
_self.width = _width; //设置默认最大宽度
_self.fontSize = 30; //默认字体大小
_self.widthProportion = function () {
let p = (document.body && document.body.clientWidth || document.getElementsByTagName("html")[0].offsetWidth) / _self.width;
return p > 1 ? 1 : p < 0.38 ? 0.38 : p;
};
_self.changePage = function () {
document.getElementsByTagName("html")[0].setAttribute("style", "font-size:" + _self.widthProportion() * _self.fontSize + "px !important");
};
_self.changePage();
window.addEventListener('resize', function () {
_self.changePage();
}, false);
};
//
let scale = $A(window).width() / _width;
$A(".__auto").each(function () {
if ($A(this).attr("data-original") !== "1") {
$A(this).attr("data-original-top", parseInt($A(this).css("top")));
$A(this).attr("data-original-right", parseInt($A(this).css("right")));
$A(this).attr("data-original-bottom", parseInt($A(this).css("bottom")));
$A(this).attr("data-original-left", parseInt($A(this).css("left")));
$A(this).attr("data-original-width", parseInt($A(this).css("width")));
$A(this).attr("data-original-height", parseInt($A(this).css("height")));
$A(this).attr("data-original-line-height", parseInt($A(this).css("line-height")));
$A(this).attr("data-original", "1");
}
let _t = parseInt($A(this).attr("data-original-top"));
let _r = parseInt($A(this).attr("data-original-right"));
let _b = parseInt($A(this).attr("data-original-bottom"));
let _l = parseInt($A(this).attr("data-original-left"));
let _w = parseInt($A(this).attr("data-original-width"));
let _h = parseInt($A(this).attr("data-original-height"));
let _lh = parseInt($A(this).attr("data-original-line-height"));
//
let _css = {};
if (_t > 0) _css['top'] = _t * scale;
if (_r > 0) _css['right'] = _r * scale;
if (_b > 0) _css['bottom'] = _b * scale;
if (_l > 0) _css['left'] = _l * scale;
if (_w > 0) _css['width'] = _w * scale;
if (_h > 0) _css['height'] = _h * scale;
if (_lh > 0) _css['line-height'] = (_lh * scale) + 'px';
$A(this).css(_css);
});
return scale;
},
/**
* 动态加载js文件
* @param url
@ -1020,15 +891,160 @@
this.loadCss(urls[0], recursiveCallback);
},
__loadCss: {},
/**
* 对象中有Date格式的转成指定格式
* @param params
* @param format 默认格式Y-m-d H:i:s
* @returns {*}
*/
date2string(params, format) {
if (params === null) {
return params;
}
if (typeof format === "undefined") {
format = "Y-m-d H:i:s";
}
if (params instanceof Date) {
params = $A.formatDate(format, params);
} else if ($A.isJson(params)) {
for (let key in params) {
if (!params.hasOwnProperty(key)) continue;
params[key] = $A.date2string(params[key], format);
}
} else if ($A.isArray(params)) {
params.forEach((val, index) => {
params[index] = $A.date2string(val, format);
});
}
return params;
},
/**
* 字节转换
* @param bytes
* @returns {string}
*/
bytesToSize(bytes) {
if (bytes === 0) return '0 B';
let k = 1024;
let sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let i = Math.floor(Math.log(bytes) / Math.log(k));
if (typeof sizes[i] === "undefined") {
return '0 B';
}
return $A.runNum((bytes / Math.pow(k, i)), 2) + ' ' + sizes[i];
},
/**
* html代码转义
* @param sHtml
* @returns {*}
*/
html2Escape(sHtml) {
if (!sHtml || sHtml == '') {
return '';
}
return sHtml.replace(/[<>&"]/g, function (c) {
return {'<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;'}[c];
});
},
});
/**
* =============================================================================
* **************************** ihttp ****************************
* ******************************** storage ********************************
* =============================================================================
*/
$.extend({
setStorage(key, value) {
return this.storage(key, value);
},
getStorage(key, def = null) {
let value = this.storage(key);
return value || def;
},
getStorageString(key, def = '') {
let value = this.storage(key);
return typeof value === "string" || typeof value === "number" ? value : def;
},
getStorageInt(key, def = 0) {
let value = this.storage(key);
return typeof value === "number" ? value : def;
},
getStorageBoolean(key, def = false) {
let value = this.storage(key);
return typeof value === "boolean" ? value : def;
},
getStorageArray(key, def = []) {
let value = this.storage(key);
return this.isArray(value) ? value : def;
},
getStorageJson(key, def = {}) {
let value = this.storage(key);
return this.isJson(value) ? value : def;
},
storage(key, value) {
if (!key) {
return;
}
let keyName = '__state__';
if (key.substring(0, 5) === 'cache') {
keyName = '__state:' + key + '__';
}
if (typeof value === 'undefined') {
return this.loadFromlLocal(key, '', keyName);
} else {
this.savaToLocal(key, value, keyName);
}
},
savaToLocal(key, value, keyName) {
try {
if (typeof keyName === 'undefined') keyName = '__seller__';
let seller = window.localStorage[keyName];
if (!seller) {
seller = {};
} else {
seller = JSON.parse(seller);
}
seller[key] = value;
window.localStorage[keyName] = JSON.stringify(seller);
} catch (e) {
}
},
loadFromlLocal(key, def, keyName) {
try {
if (typeof keyName === 'undefined') keyName = '__seller__';
let seller = window.localStorage[keyName];
if (!seller) {
return def;
}
seller = JSON.parse(seller);
if (!seller || typeof seller[key] === 'undefined') {
return def;
}
return seller[key];
} catch (e) {
return def;
}
},
});
/**
* =============================================================================
* ********************************* ihttp *********************************
* =============================================================================
*/
$.extend({
serializeObject (obj, parents) {
if (typeof obj === 'string') return obj;
let resultArray = [];
@ -1373,7 +1389,6 @@
* =============================================================================
*/
$.extend({
ajaxc(params) {
if (!params) return false;
if (typeof params.url === 'undefined') return false;
@ -1414,191 +1429,5 @@
}
});
/**
* =============================================================================
* ***************************** manage assist ****************************
* =============================================================================
*/
$.extend({
/**
* 对象中有Date格式的转成指定格式
* @param params
* @param format 默认格式Y-m-d H:i:s
* @returns {*}
*/
date2string(params, format) {
if (params === null) {
return params;
}
if (typeof format === "undefined") {
format = "Y-m-d H:i:s";
}
if (params instanceof Date) {
params = $A.formatDate(format, params);
} else if ($A.isJson(params)) {
for (let key in params) {
if (!params.hasOwnProperty(key)) continue;
params[key] = $A.date2string(params[key], format);
}
} else if ($A.isArray(params)) {
params.forEach((val, index) => {
params[index] = $A.date2string(val, format);
});
}
return params;
},
/**
* 获取一些指定时间
* @param str
* @param retInt
* @returns {*|string}
*/
getData(str, retInt = false) {
let now = new Date(); //当前日期
let nowDayOfWeek = now.getDay(); //今天本周的第几天
let nowDay = now.getDate(); //当前日
let nowMonth = now.getMonth(); //当前月
let nowYear = now.getYear(); //当前年
nowYear += (nowYear < 2000) ? 1900 : 0;
let lastMonthDate = new Date(); //上月日期
lastMonthDate.setDate(1);
lastMonthDate.setMonth(lastMonthDate.getMonth()-1);
let lastMonth = lastMonthDate.getMonth();
let getQuarterStartMonth = () => {
let quarterStartMonth = 0;
if(nowMonth < 3) {
quarterStartMonth = 0;
}
if (2 < nowMonth && nowMonth < 6) {
quarterStartMonth = 3;
}
if (5 < nowMonth && nowMonth < 9) {
quarterStartMonth = 6;
}
if (nowMonth > 8) {
quarterStartMonth = 9;
}
return quarterStartMonth;
};
let getMonthDays = (myMonth) => {
let monthStartDate = new Date(nowYear, myMonth, 1);
let monthEndDate = new Date(nowYear, myMonth + 1, 1);
return (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
};
//
let time = now.getTime();
switch (str) {
case '今天':
time = now;
break;
case '昨天':
time = now - 86400000;
break;
case '前天':
time = now - 86400000 * 2;
break;
case '本周':
time = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);
break;
case '本周结束':
time = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));
break;
case '上周':
time = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek - 7);
break;
case '上周结束':
time = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek - 1);
break;
case '本周2':
time = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek + 1);
break;
case '本周结束2':
time = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek) + 1);
break;
case '上周2':
time = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek - 7 + 1);
break;
case '上周结束2':
time = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek - 1 + 1);
break;
case '本月':
time = new Date(nowYear, nowMonth, 1);
break;
case '本月结束':
time = new Date(nowYear, nowMonth, getMonthDays(nowMonth));
break;
case '上个月':
time = new Date(nowYear, lastMonth, 1);
break;
case '上个月结束':
time = new Date(nowYear, lastMonth, getMonthDays(lastMonth));
break;
case '本季度':
time = new Date(nowYear, getQuarterStartMonth(), 1);
break;
case '本季度结束':
let quarterEndMonth = getQuarterStartMonth() + 2;
time = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth));
break;
}
if (retInt === true) {
return time;
}
return $A.formatDate("Y-m-d", parseInt(time / 1000))
},
/**
* 字节转换
* @param bytes
* @returns {string}
*/
bytesToSize(bytes) {
if (bytes === 0) return '0 B';
let k = 1024;
let sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let i = Math.floor(Math.log(bytes) / Math.log(k));
if (typeof sizes[i] === "undefined") {
return '0 B';
}
return $A.runNum((bytes / Math.pow(k, i)), 2) + ' ' + sizes[i];
},
/**
* html代码转义
* @param sHtml
* @returns {*}
*/
html2Escape(sHtml) {
if (!sHtml || sHtml == '') {
return '';
}
return sHtml.replace(/[<>&"]/g, function (c) {
return {'<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;'}[c];
});
},
/**
* 搜索高亮
* @param string
* @param key
* @returns {string|*}
*/
sreachHighlight(string, key) {
if (!string || string == '') {
return '';
}
if (!key || key == '') {
return $A.html2Escape(string);
}
string = $A.html2Escape(string.replace(new RegExp(key, "g"), "[highlight]" + key + "[/highlight]"));
string = string.replace(/\[highlight\]/g, '<span class="sreach-highlight">');
string = string.replace(/\[\/highlight\]/g, '</span>');
return string;
},
});
window.$A = $;
})(window, window.$ = window.jQuery = require('jquery'));

View File

@ -3,6 +3,180 @@
*/
(function (window) {
const $ = window.$A;
/**
* =============================================================================
* ******************************* web extra *******************************
* =============================================================================
*/
$.extend({
/**
* 接口地址
* @param str
* @returns {string|string|*}
*/
apiUrl(str) {
if (str.substring(0, 2) === "//" ||
str.substring(0, 7) === "http://" ||
str.substring(0, 8) === "https://" ||
str.substring(0, 6) === "ftp://" ||
str.substring(0, 1) === "/") {
return str;
}
if (window.systemInformation && typeof window.systemInformation.apiUrl === "string") {
str = window.systemInformation.apiUrl + str;
} else {
str = window.location.origin + "/api/" + str;
}
while (str.indexOf("/../") !== -1) {
str = str.replace(/\/(((?!\/).)*)\/\.\.\//, "/")
}
return str
},
/**
* 服务器地址
* @param str
* @returns {string}
*/
originUrl(str) {
if (str.substring(0, 2) === "//" ||
str.substring(0, 7) === "http://" ||
str.substring(0, 8) === "https://" ||
str.substring(0, 6) === "ftp://" ||
str.substring(0, 1) === "/") {
return str;
}
if (window.systemInformation && typeof window.systemInformation.origin === "string") {
str = window.systemInformation.origin + str;
} else {
str = window.location.origin + "/" + str;
}
while (str.indexOf("/../") !== -1) {
str = str.replace(/\/(((?!\/).)*)\/\.\.\//, "/")
}
return str
},
/**
* 项目配置模板
* @param project_id
* @returns {{showMy: boolean, showUndone: boolean, project_id, chat: boolean, showHelp: boolean, showCompleted: boolean, cardInit: boolean, card: boolean, completedTask: boolean}}
*/
projectParameterTemplate(project_id) {
return {
project_id,
card: true,
cardInit: false,
chat: false,
showMy: true,
showHelp: true,
showUndone: true,
showCompleted: false,
completedTask: false,
}
},
/**
* 获取一些指定时间
* @param str
* @param retInt
* @returns {*|string}
*/
getData(str, retInt = false) {
let now = new Date(); //当前日期
let nowDayOfWeek = now.getDay(); //今天本周的第几天
let nowDay = now.getDate(); //当前日
let nowMonth = now.getMonth(); //当前月
let nowYear = now.getYear(); //当前年
nowYear += (nowYear < 2000) ? 1900 : 0;
let lastMonthDate = new Date(); //上月日期
lastMonthDate.setDate(1);
lastMonthDate.setMonth(lastMonthDate.getMonth()-1);
let lastMonth = lastMonthDate.getMonth();
let getQuarterStartMonth = () => {
let quarterStartMonth = 0;
if(nowMonth < 3) {
quarterStartMonth = 0;
}
if (2 < nowMonth && nowMonth < 6) {
quarterStartMonth = 3;
}
if (5 < nowMonth && nowMonth < 9) {
quarterStartMonth = 6;
}
if (nowMonth > 8) {
quarterStartMonth = 9;
}
return quarterStartMonth;
};
let getMonthDays = (myMonth) => {
let monthStartDate = new Date(nowYear, myMonth, 1);
let monthEndDate = new Date(nowYear, myMonth + 1, 1);
return (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
};
//
let time = now.getTime();
switch (str) {
case '今天':
time = now;
break;
case '昨天':
time = now - 86400000;
break;
case '前天':
time = now - 86400000 * 2;
break;
case '本周':
time = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);
break;
case '本周结束':
time = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));
break;
case '上周':
time = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek - 7);
break;
case '上周结束':
time = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek - 1);
break;
case '本周2':
time = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek + 1);
break;
case '本周结束2':
time = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek) + 1);
break;
case '上周2':
time = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek - 7 + 1);
break;
case '上周结束2':
time = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek - 1 + 1);
break;
case '本月':
time = new Date(nowYear, nowMonth, 1);
break;
case '本月结束':
time = new Date(nowYear, nowMonth, getMonthDays(nowMonth));
break;
case '上个月':
time = new Date(nowYear, lastMonth, 1);
break;
case '上个月结束':
time = new Date(nowYear, lastMonth, getMonthDays(lastMonth));
break;
case '本季度':
time = new Date(nowYear, getQuarterStartMonth(), 1);
break;
case '本季度结束':
let quarterEndMonth = getQuarterStartMonth() + 2;
time = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth));
break;
}
if (retInt === true) {
return time;
}
return $A.formatDate("Y-m-d", parseInt(time / 1000))
},
});
/**
* =============================================================================
* ***************************** iviewui assist ****************************

View File

@ -60,11 +60,11 @@ export default {
loadIng: 0,
codeNeed: false,
codeUrl: this.$store.state.method.apiUrl('users/login/codeimg'),
codeUrl: $A.apiUrl('users/login/codeimg'),
loginType: 'login',
loginJump: false,
email: this.$store.state.method.getStorageString("cacheLoginEmail") || '',
email: $A.getStorageString("cacheLoginEmail") || '',
password: '',
password2: '',
code: '',
@ -140,7 +140,7 @@ export default {
},
reCode() {
this.codeUrl = this.$store.state.method.apiUrl('users/login/codeimg?_=' + Math.random())
this.codeUrl = $A.apiUrl('users/login/codeimg?_=' + Math.random())
},
onServerUrlInput() {
@ -159,7 +159,7 @@ export default {
this.$store.dispatch("call", {
url: value + 'system/setting',
}).then(() => {
this.$store.state.method.setStorage("cacheServerUrl", value)
$A.setStorage("cacheServerUrl", value)
window.location.reload();
}).catch(({msg}) => {
$A.modalError(msg || "服务器地址无效", 301);
@ -167,14 +167,14 @@ export default {
});
return;
}
this.$store.state.method.setStorage("cacheServerUrl", "")
$A.setStorage("cacheServerUrl", "")
window.location.reload();
}
});
},
onServerUrlClear() {
this.$store.state.method.setStorage("cacheServerUrl", "")
$A.setStorage("cacheServerUrl", "")
window.location.reload();
},
@ -224,7 +224,7 @@ export default {
},
}).then(({data}) => {
this.loadIng--;
this.$store.state.method.setStorage("cacheLoginEmail", this.email)
$A.setStorage("cacheLoginEmail", this.email)
this.$store.dispatch("handleClearCache", data).then(() => {
this.goNext1();
}).catch(() => {

View File

@ -240,8 +240,8 @@ export default {
},
mounted() {
if (this.$store.state.method.getStorageString("clearCache")) {
this.$store.state.method.setStorage("clearCache", "")
if ($A.getStorageString("clearCache")) {
$A.setStorage("clearCache", "")
$A.messageSuccess("清除成功");
}
//
@ -494,7 +494,7 @@ export default {
return;
case 'clearCache':
this.$store.dispatch("handleClearCache", null).then(() => {
this.$store.state.method.setStorage("clearCache", $A.randomString(6))
$A.setStorage("clearCache", $A.randomString(6))
window.location.reload()
}).catch(() => {
window.location.reload()
@ -612,7 +612,7 @@ export default {
}
this.goForward({path: '/manage/messenger'});
if (data.dialog_id) {
this.$store.state.method.setStorage("messenger::dialogId", data.dialog_id)
$A.setStorage("messenger::dialogId", data.dialog_id)
this.$store.state.dialogOpenId = data.dialog_id;
}
}

View File

@ -35,7 +35,7 @@ export default {
data() {
return {
uploadFormat: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz', 'ai', 'avi', 'bmp', 'cdr', 'eps', 'mov', 'mp3', 'mp4', 'pr', 'psd', 'svg', 'tif'],
actionUrl: this.$store.state.method.apiUrl('dialog/msg/sendfile'),
actionUrl: $A.apiUrl('dialog/msg/sendfile'),
}
},
@ -44,7 +44,7 @@ export default {
headers() {
return {
fd: this.$store.state.method.getStorageString("userWsFd"),
fd: $A.getStorageString("userWsFd"),
token: this.userToken,
}
},

View File

@ -196,7 +196,7 @@ export default {
previewUrl() {
if (this.isPreview) {
return this.$store.state.method.apiUrl("../fileview/onlinePreview?url=" + encodeURIComponent(this.contentDetail.url))
return $A.apiUrl("../fileview/onlinePreview?url=" + encodeURIComponent(this.contentDetail.url))
} else {
return '';
}

View File

@ -113,7 +113,7 @@ export default {
previewUrl() {
if (this.isPreview) {
return this.$store.state.method.apiUrl("../fileview/onlinePreview?url=" + encodeURIComponent(this.contentDetail.url))
return $A.apiUrl("../fileview/onlinePreview?url=" + encodeURIComponent(this.contentDetail.url))
} else {
return '';
}

View File

@ -218,7 +218,7 @@ export default {
}
},
'addData.project_id'(id) {
this.$store.state.method.setStorage("cacheAddTaskProjectId", id);
$A.setStorage("cacheAddTaskProjectId", id);
},
'addData.column_id'(id) {
const {project_id, column_id} = this.addData;
@ -229,7 +229,7 @@ export default {
this.$set(this.addData, 'cascader', []);
}
})
this.$store.state.method.setStorage("cacheAddTaskColumnId", id);
$A.setStorage("cacheAddTaskColumnId", id);
}
},
methods: {
@ -314,8 +314,8 @@ export default {
this.addData.column_id = column.id;
}
} else {
let cacheAddTaskProjectId = this.$store.state.method.getStorageInt("cacheAddTaskProjectId");
let cacheAddTaskColumnId = this.$store.state.method.getStorageInt("cacheAddTaskColumnId");
let cacheAddTaskProjectId = $A.getStorageInt("cacheAddTaskProjectId");
let cacheAddTaskColumnId = $A.getStorageInt("cacheAddTaskColumnId");
let project = this.projects.find(({id}) => id == this.projectId)
|| this.projects.find(({id}) => id == cacheAddTaskProjectId)
|| this.projects.find(({id}) => id > 0);

View File

@ -1115,7 +1115,7 @@ export default {
this.$nextTick(() => {
if (this.$store.state.windowMax768) {
this.goForward({path: '/manage/messenger', query: {sendmsg: this.msgText}});
this.$store.state.method.setStorage("messenger::dialogId", data.dialog_id)
$A.setStorage("messenger::dialogId", data.dialog_id)
this.$store.state.dialogOpenId = data.dialog_id;
this.$store.dispatch('openTask', 0);
} else {
@ -1148,7 +1148,7 @@ export default {
}
this.$nextTick(() => {
this.goForward({path: '/manage/messenger', query: {sendmsg: this.msgText}});
this.$store.state.method.setStorage("messenger::dialogId", data.dialog_id)
$A.setStorage("messenger::dialogId", data.dialog_id)
this.$store.state.dialogOpenId = data.dialog_id;
this.$store.dispatch('openTask', 0);
});

View File

@ -31,7 +31,7 @@ export default {
data() {
return {
uploadFormat: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz', 'ai', 'avi', 'bmp', 'cdr', 'eps', 'mov', 'mp3', 'mp4', 'pr', 'psd', 'svg', 'tif'],
actionUrl: this.$store.state.method.apiUrl('project/task/upload'),
actionUrl: $A.apiUrl('project/task/upload'),
}
},
@ -40,7 +40,7 @@ export default {
headers() {
return {
fd: this.$store.state.method.getStorageString("userWsFd"),
fd: $A.getStorageString("userWsFd"),
token: this.userToken,
}
},

View File

@ -312,7 +312,7 @@ export default {
searchKey: '',
searchTimeout: null,
pid: this.$store.state.method.getStorageInt("fileOpenPid"),
pid: $A.getStorageInt("fileOpenPid"),
shearId: 0,
types: [
@ -372,7 +372,7 @@ export default {
],
tableHeight: 500,
tableMode: this.$store.state.method.getStorageBoolean("fileTableMode"),
tableMode: $A.getStorageBoolean("fileTableMode"),
columns: [],
shareShow: false,
@ -433,12 +433,12 @@ export default {
...mapState(['userId', 'userToken', 'userIsAdmin', 'userInfo', 'files']),
actionUrl() {
return this.$store.state.method.apiUrl('file/content/upload?pid=' + this.pid)
return $A.apiUrl('file/content/upload?pid=' + this.pid)
},
headers() {
return {
fd: this.$store.state.method.getStorageString("userWsFd"),
fd: $A.getStorageString("userWsFd"),
token: this.userToken,
}
},
@ -496,7 +496,7 @@ export default {
},
tableMode(val) {
this.$store.state.method.setStorage("fileTableMode", val)
$A.setStorage("fileTableMode", val)
},
fileShow(val) {
@ -689,7 +689,7 @@ export default {
this.loadIng++;
this.$store.dispatch("getFiles", this.pid).then(() => {
this.loadIng--;
this.$store.state.method.setStorage("fileOpenPid", this.pid)
$A.setStorage("fileOpenPid", this.pid)
}).catch(({msg}) => {
$A.modalError(msg);
this.loadIng--;

View File

@ -221,17 +221,17 @@ export default {
closeDialog() {
this.dialogId = 0;
this.$store.state.method.setStorage("messenger::dialogId", 0)
$A.setStorage("messenger::dialogId", 0)
},
openDialog(dialog, smooth) {
this.$store.state.method.setStorage("messenger::dialogId", dialog.id)
$A.setStorage("messenger::dialogId", dialog.id)
this.dialogId = dialog.id;
this.scrollIntoActive(smooth);
},
openDialogStorage() {
this.dialogId = this.$store.state.method.getStorageInt("messenger::dialogId")
this.dialogId = $A.getStorageInt("messenger::dialogId")
if (this.dialogId > 0) {
const dialog = this.dialogs.find(({id}) => id === this.dialogId);
dialog && this.openDialog(dialog, false);

View File

@ -9,16 +9,16 @@ export default {
* @returns {Promise<unknown>}
*/
call({state, dispatch}, params) {
if (!state.method.isJson(params)) params = {url: params}
if (!state.method.isJson(params.header)) params.header = {}
params.url = state.method.apiUrl(params.url);
params.data = state.method.date2string(params.data);
if (!$A.isJson(params)) params = {url: params}
if (!$A.isJson(params.header)) params.header = {}
params.url = $A.apiUrl(params.url);
params.data = $A.date2string(params.data);
params.header['Content-Type'] = 'application/json';
params.header['language'] = $A.getLanguage();
params.header['token'] = state.userToken;
params.header['fd'] = state.method.getStorageString("userWsFd");
params.header['fd'] = $A.getStorageString("userWsFd");
//
const cloneParams = state.method.cloneJSON(params);
const cloneParams = $A.cloneJSON(params);
return new Promise(function (resolve, reject) {
if (params.spinner === true) {
params.before = () => {
@ -31,7 +31,7 @@ export default {
}
//
params.success = (result, status, xhr) => {
if (!state.method.isJson(result)) {
if (!$A.isJson(result)) {
console.log(result, status, xhr);
reject({data: {}, msg: "Return error"})
return;
@ -77,7 +77,7 @@ export default {
};
//
if (params.websocket === true || params.ws === true) {
const apiWebsocket = state.method.randomString(16);
const apiWebsocket = $A.randomString(16);
const apiTimeout = setTimeout(() => {
const WListener = state.ajaxWsListener.find((item) => item.apiWebsocket == apiWebsocket);
if (WListener) {
@ -143,23 +143,23 @@ export default {
//
let key = data;
let project_id = state.projectId;
if (state.method.isJson(data)) {
if ($A.isJson(data)) {
key = data.key;
project_id = data.project_id;
}
if (project_id) {
let index = state.cacheProjectParameter.findIndex(item => item.project_id == project_id)
if (index === -1) {
state.cacheProjectParameter.push(state.method.projectParameterTemplate(project_id));
state.cacheProjectParameter.push($A.projectParameterTemplate(project_id));
index = state.cacheProjectParameter.findIndex(item => item.project_id == project_id)
}
const cache = state.cacheProjectParameter[index];
if (!state.method.isJson(key)) {
if (!$A.isJson(key)) {
key = {[key]: !cache[key]};
}
state.cacheProjectParameter.splice(index, 1, Object.assign(cache, key))
setTimeout(() => {
state.method.setStorage("cacheProjectParameter", state.cacheProjectParameter);
$A.setStorage("cacheProjectParameter", state.cacheProjectParameter);
});
}
},
@ -192,14 +192,14 @@ export default {
*/
saveUserInfo({state, dispatch}, info) {
return new Promise(function (resolve) {
const userInfo = state.method.cloneJSON(info);
userInfo.userid = state.method.runNum(userInfo.userid);
const userInfo = $A.cloneJSON(info);
userInfo.userid = $A.runNum(userInfo.userid);
userInfo.token = userInfo.userid > 0 ? (userInfo.token || state.userToken) : '';
state.userInfo = userInfo;
state.userId = userInfo.userid;
state.userToken = userInfo.token;
state.userIsAdmin = state.method.inArray('admin', userInfo.identity);
state.method.setStorage("userInfo", state.userInfo);
state.userIsAdmin = $A.inArray('admin', userInfo.identity);
$A.setStorage("userInfo", state.userInfo);
dispatch("getProjects");
dispatch("getDialogs");
dispatch("getTaskForDashboard");
@ -233,7 +233,7 @@ export default {
}
//
let time = $A.Time();
let list = state.method.cloneJSON(state.cacheUserWait);
let list = $A.cloneJSON(state.cacheUserWait);
if (data && data.userid) {
list.push(data)
}
@ -299,7 +299,7 @@ export default {
state.cacheUserActive = Object.assign(data, {__:Math.random()});
Store.set('cacheUserActive', data);
setTimeout(() => {
state.method.setStorage("cacheUserBasic", state.cacheUserBasic);
$A.setStorage("cacheUserBasic", state.cacheUserBasic);
})
},
@ -375,7 +375,7 @@ export default {
handleClearCache({state, dispatch}, userInfo) {
return new Promise(function (resolve, reject) {
try {
const cacheLoginEmail = state.method.getStorageString("cacheLoginEmail");
const cacheLoginEmail = $A.getStorageString("cacheLoginEmail");
//
window.localStorage.clear();
//
@ -385,10 +385,10 @@ export default {
state.cacheColumns = state.columns = [];
state.cacheTasks = state.tasks = [];
//
state.method.setStorage("cacheProjectParameter", state.cacheProjectParameter);
state.method.setStorage("cacheServerUrl", state.cacheServerUrl);
state.method.setStorage("cacheLoginEmail", cacheLoginEmail);
dispatch("saveUserInfo", state.method.isJson(userInfo) ? userInfo : state.userInfo);
$A.setStorage("cacheProjectParameter", state.cacheProjectParameter);
$A.setStorage("cacheServerUrl", state.cacheServerUrl);
$A.setStorage("cacheLoginEmail", cacheLoginEmail);
dispatch("saveUserInfo", $A.isJson(userInfo) ? userInfo : state.userInfo);
//
resolve()
} catch (e) {
@ -410,11 +410,11 @@ export default {
saveFile({state, dispatch}, data) {
$A.execMainDispatch("saveFile", data)
//
if (state.method.isArray(data)) {
if ($A.isArray(data)) {
data.forEach((file) => {
dispatch("saveFile", file);
});
} else if (state.method.isJson(data)) {
} else if ($A.isJson(data)) {
let index = state.files.findIndex(({id}) => id == data.id);
if (index > -1) {
state.files.splice(index, 1, Object.assign({}, state.files[index], data));
@ -508,11 +508,11 @@ export default {
saveProject({state, dispatch}, data) {
$A.execMainDispatch("saveProject", data)
//
if (state.method.isArray(data)) {
if ($A.isArray(data)) {
data.forEach((project) => {
dispatch("saveProject", project)
});
} else if (state.method.isJson(data)) {
} else if ($A.isJson(data)) {
if (typeof data.project_column !== "undefined") {
dispatch("saveColumn", data.project_column)
delete data.project_column;
@ -524,7 +524,7 @@ export default {
state.projects.push(data);
}
setTimeout(() => {
state.method.setStorage("cacheProjects", state.cacheProjects = state.projects);
$A.setStorage("cacheProjects", state.cacheProjects = state.projects);
})
}
},
@ -553,7 +553,7 @@ export default {
}
}
setTimeout(() => {
state.method.setStorage("cacheProjects", state.cacheProjects = state.projects);
$A.setStorage("cacheProjects", state.cacheProjects = state.projects);
})
},
@ -597,7 +597,7 @@ export default {
*/
getProjectOne({state, dispatch}, project_id) {
return new Promise(function (resolve, reject) {
if (state.method.runNum(project_id) === 0) {
if ($A.runNum(project_id) === 0) {
reject({msg: 'Parameter error'});
return;
}
@ -627,7 +627,7 @@ export default {
*/
archivedProject({state, dispatch}, project_id) {
return new Promise(function (resolve, reject) {
if (state.method.runNum(project_id) === 0) {
if ($A.runNum(project_id) === 0) {
reject({msg: 'Parameter error'});
return;
}
@ -655,7 +655,7 @@ export default {
*/
removeProject({state, dispatch}, project_id) {
return new Promise(function (resolve, reject) {
if (state.method.runNum(project_id) === 0) {
if ($A.runNum(project_id) === 0) {
reject({msg: 'Parameter error'});
return;
}
@ -683,7 +683,7 @@ export default {
*/
exitProject({state, dispatch}, project_id) {
return new Promise(function (resolve, reject) {
if (state.method.runNum(project_id) === 0) {
if ($A.runNum(project_id) === 0) {
reject({msg: 'Parameter error'});
return;
}
@ -716,11 +716,11 @@ export default {
saveColumn({state, dispatch}, data) {
$A.execMainDispatch("saveColumn", data)
//
if (state.method.isArray(data)) {
if ($A.isArray(data)) {
data.forEach((column) => {
dispatch("saveColumn", column)
});
} else if (state.method.isJson(data)) {
} else if ($A.isJson(data)) {
let index = state.columns.findIndex(({id}) => id == data.id);
if (index > -1) {
state.columns.splice(index, 1, Object.assign({}, state.columns[index], data));
@ -728,7 +728,7 @@ export default {
state.columns.push(data);
}
setTimeout(() => {
state.method.setStorage("cacheColumns", state.cacheColumns = state.columns);
$A.setStorage("cacheColumns", state.cacheColumns = state.columns);
})
}
},
@ -755,7 +755,7 @@ export default {
Array.from(new Set(project_ids)).some(id => dispatch("getProjectOne", id))
//
setTimeout(() => {
state.method.setStorage("cacheColumns", state.cacheColumns = state.columns);
$A.setStorage("cacheColumns", state.cacheColumns = state.columns);
})
},
@ -819,7 +819,7 @@ export default {
*/
removeColumn({state, dispatch}, column_id) {
return new Promise(function (resolve, reject) {
if (state.method.runNum(column_id) === 0) {
if ($A.runNum(column_id) === 0) {
reject({msg: 'Parameter error'});
return;
}
@ -851,11 +851,11 @@ export default {
saveTask({state, dispatch}, data) {
$A.execMainDispatch("saveTask", data)
//
if (state.method.isArray(data)) {
if ($A.isArray(data)) {
data.forEach((task) => {
dispatch("saveTask", task)
});
} else if (state.method.isJson(data)) {
} else if ($A.isJson(data)) {
data._time = $A.Time();
let index = state.tasks.findIndex(({id}) => id == data.id);
if (index > -1) {
@ -881,7 +881,7 @@ export default {
}
//
setTimeout(() => {
state.method.setStorage("cacheTasks", state.cacheTasks = state.tasks);
$A.setStorage("cacheTasks", state.cacheTasks = state.tasks);
})
}
},
@ -915,7 +915,7 @@ export default {
state.taskId = 0;
}
setTimeout(() => {
state.method.setStorage("cacheTasks", state.cacheTasks = state.tasks);
$A.setStorage("cacheTasks", state.cacheTasks = state.tasks);
})
},
@ -1002,7 +1002,7 @@ export default {
*/
getTaskOne({state, dispatch}, task_id) {
return new Promise(function (resolve, reject) {
if (state.method.runNum(task_id) === 0) {
if ($A.runNum(task_id) === 0) {
reject({msg: 'Parameter error'});
return;
}
@ -1131,7 +1131,7 @@ export default {
*/
removeTask({state, dispatch}, task_id) {
return new Promise(function (resolve, reject) {
if (state.method.runNum(task_id) === 0) {
if ($A.runNum(task_id) === 0) {
reject({msg: 'Parameter error'});
return;
}
@ -1160,7 +1160,7 @@ export default {
*/
archivedTask({state, dispatch}, task_id) {
return new Promise(function (resolve, reject) {
if (state.method.runNum(task_id) === 0) {
if ($A.runNum(task_id) === 0) {
reject({msg: 'Parameter error'});
return;
}
@ -1189,7 +1189,7 @@ export default {
*/
getTaskContent({state, dispatch}, task_id) {
return new Promise(function (resolve, reject) {
if (state.method.runNum(task_id) === 0) {
if ($A.runNum(task_id) === 0) {
reject({msg: 'Parameter error'});
return;
}
@ -1222,7 +1222,7 @@ export default {
*/
getTaskFiles({state, dispatch}, task_id) {
return new Promise(function (resolve, reject) {
if (state.method.runNum(task_id) === 0) {
if ($A.runNum(task_id) === 0) {
reject({msg: 'Parameter error'});
return;
}
@ -1276,7 +1276,7 @@ export default {
*/
openTask({state, dispatch}, task) {
let task_id = task;
if (state.method.isJson(task)) {
if ($A.isJson(task)) {
if (task.parent_id > 0) {
task_id = task.parent_id;
} else {
@ -1309,8 +1309,8 @@ export default {
*/
taskAdd({state, dispatch}, data) {
return new Promise(function (resolve, reject) {
const post = state.method.cloneJSON(state.method.date2string(data));
if (state.method.isArray(post.column_id)) post.column_id = post.column_id.find((val) => val)
const post = $A.cloneJSON($A.date2string(data));
if ($A.isArray(post.column_id)) post.column_id = post.column_id.find((val) => val)
//
dispatch("call", {
url: 'project/task/add',
@ -1374,7 +1374,7 @@ export default {
*/
taskUpdate({state, dispatch}, data) {
return new Promise(function (resolve, reject) {
const post = state.method.cloneJSON(state.method.date2string(data));
const post = $A.cloneJSON($A.date2string(data));
//
dispatch("call", {
url: 'project/task/update',
@ -1424,11 +1424,11 @@ export default {
saveDialog({state, dispatch}, data) {
$A.execMainDispatch("saveDialog", data)
//
if (state.method.isArray(data)) {
if ($A.isArray(data)) {
data.forEach((dialog) => {
dispatch("saveDialog", dialog)
});
} else if (state.method.isJson(data)) {
} else if ($A.isJson(data)) {
let index = state.dialogs.findIndex(({id}) => id == data.id);
if (index > -1) {
state.dialogs.splice(index, 1, Object.assign({}, state.dialogs[index], data));
@ -1436,7 +1436,7 @@ export default {
state.dialogs.push(data);
}
setTimeout(() => {
state.method.setStorage("cacheDialogs", state.cacheDialogs = state.dialogs);
$A.setStorage("cacheDialogs", state.cacheDialogs = state.dialogs);
})
}
},
@ -1455,7 +1455,7 @@ export default {
dispatch("saveDialog", {
id: data.dialog_id,
last_msg: data,
last_at: state.method.formatDate("Y-m-d H:i:s")
last_at: $A.formatDate("Y-m-d H:i:s")
});
} else {
dispatch("getDialogOne", data.dialog_id);
@ -1490,7 +1490,7 @@ export default {
*/
getDialogOne({state, dispatch}, dialog_id) {
return new Promise(function (resolve, reject) {
if (state.method.runNum(dialog_id) === 0) {
if ($A.runNum(dialog_id) === 0) {
reject({msg: 'Parameter error'});
return;
}
@ -1528,7 +1528,7 @@ export default {
},
}).then(result => {
dispatch("saveDialog", result.data);
state.method.setStorage("messenger::dialogId", result.data.id);
$A.setStorage("messenger::dialogId", result.data.id);
state.dialogOpenId = result.data.id;
resolve(result);
}).catch(e => {
@ -1548,7 +1548,7 @@ export default {
//
const index = state.dialogs.findIndex(({id}) => id == dialog_id);
if (index > -1) {
const tmp = state.method.cloneJSON(state.dialogs[index]);
const tmp = $A.cloneJSON(state.dialogs[index]);
state.dialogs.splice(index, 1);
state.dialogs.unshift(tmp);
}
@ -1569,12 +1569,12 @@ export default {
state.dialogs.splice(index, 1);
}
})
if (ids.includes(state.method.getStorageInt("messenger::dialogId"))) {
state.method.setStorage("messenger::dialogId", 0)
if (ids.includes($A.getStorageInt("messenger::dialogId"))) {
$A.setStorage("messenger::dialogId", 0)
}
//
setTimeout(() => {
state.method.setStorage("cacheDialogs", state.cacheDialogs = state.dialogs);
$A.setStorage("cacheDialogs", state.cacheDialogs = state.dialogs);
})
},
@ -1591,11 +1591,11 @@ export default {
saveDialogMsg({state, dispatch}, data) {
$A.execMainDispatch("saveDialogMsg", data)
//
if (state.method.isArray(data)) {
if ($A.isArray(data)) {
data.forEach((msg) => {
dispatch("saveDialogMsg", msg)
});
} else if (state.method.isJson(data)) {
} else if ($A.isJson(data)) {
let index = state.dialogMsgs.findIndex(({id}) => id == data.id);
if (index > -1) {
state.dialogMsgs.splice(index, 1, Object.assign({}, state.dialogMsgs[index], data));
@ -1715,7 +1715,7 @@ export default {
dispatch("websocketSend", {
type: 'readMsg',
data: {
id: state.method.cloneJSON(state.wsReadWaitList)
id: $A.cloneJSON(state.wsReadWaitList)
}
});
state.wsReadWaitList = [];
@ -1738,7 +1738,7 @@ export default {
return;
}
//
let url = state.method.apiUrl('../ws');
let url = $A.apiUrl('../ws');
url = url.replace("https://", "wss://");
url = url.replace("http://", "ws://");
url += "?action=web&token=" + state.userToken;
@ -1767,11 +1767,11 @@ export default {
};
state.ws.onmessage = (e) => {
// console.log("[WS] Message", e);
const msgDetail = state.method.jsonParse(event.data);
const msgDetail = $A.jsonParse(event.data);
const {type, msgId} = msgDetail;
switch (type) {
case "open":
state.method.setStorage("userWsFd", msgDetail.data.fd)
$A.setStorage("userWsFd", msgDetail.data.fd)
break
case "receipt":
@ -1932,7 +1932,7 @@ export default {
* @param params {type, data, callback}
*/
websocketSend({state}, params) {
if (!state.method.isJson(params)) {
if (!$A.isJson(params)) {
typeof callback === "function" && callback(null, false)
return;
}
@ -1943,7 +1943,7 @@ export default {
return;
}
if (typeof callback === "function") {
msgId = state.method.randomString(16)
msgId = $A.randomString(16)
state.wsCall[msgId] = callback;
}
try {

View File

@ -7,7 +7,7 @@ export default {
projectData(state) {
let projectId = state.projectId;
if (projectId == 0) {
projectId = state.method.runNum(window.__projectId);
projectId = $A.runNum(window.__projectId);
}
if (projectId > 0) {
window.__projectId = projectId;
@ -31,7 +31,7 @@ export default {
}
let cache = state.cacheProjectParameter.find(({project_id}) => project_id == state.projectId);
if (!cache) {
cache = state.method.projectParameterTemplate(state.projectId)
cache = $A.projectParameterTemplate(state.projectId)
state.cacheProjectParameter.push(cache);
}
return cache && !!cache[key];
@ -46,7 +46,7 @@ export default {
taskData(state) {
let taskId = state.taskId;
if (taskId == 0) {
taskId = state.method.runNum(window.__taskId);
taskId = $A.runNum(window.__taskId);
}
if (taskId > 0) {
window.__taskId = taskId;

View File

@ -1,268 +1,4 @@
const method = {
apiUrl(str) {
if (str.substring(0, 2) === "//" ||
str.substring(0, 7) === "http://" ||
str.substring(0, 8) === "https://" ||
str.substring(0, 6) === "ftp://" ||
str.substring(0, 1) === "/") {
return str;
}
if (window.systemInformation && typeof window.systemInformation.apiUrl === "string") {
str = window.systemInformation.apiUrl + str;
} else {
str = window.location.origin + "/api/" + str;
}
while (str.indexOf("/../") !== -1) {
str = str.replace(/\/(((?!\/).)*)\/\.\.\//, "/")
}
return str
},
Time(v) {
let time
if (typeof v === "string" && this.strExists(v, "-")) {
v = v.replace(/-/g, '/');
time = new Date(v).getTime();
} else {
time = new Date().getTime();
}
return Math.round(time / 1000)
},
Date(v) {
if (typeof v === "string" && this.strExists(v, "-")) {
v = v.replace(/-/g, '/');
}
return new Date(v);
},
zeroFill(str, length, after) {
str+= "";
if (str.length >= length) {
return str;
}
let _str = '', _ret = '';
for (let i = 0; i < length; i++) {
_str += '0';
}
if (after || typeof after === 'undefined') {
_ret = (_str + "" + str).substr(length * -1);
} else {
_ret = (str + "" + _str).substr(0, length);
}
return _ret;
},
formatDate(format, v) {
if (typeof format === 'undefined' || format === '') {
format = 'Y-m-d H:i:s';
}
let dateObj;
if (v instanceof Date) {
dateObj = v;
} else {
if (typeof v === 'undefined') {
dateObj = new Date();
} else if (/^(-)?\d{1,10}$/.test(v)) {
dateObj = new Date(v * 1000);
} else {
dateObj = this.Date(v);
}
}
//
format = format.replace(/Y/g, dateObj.getFullYear() + "");
format = format.replace(/m/g, this.zeroFill(dateObj.getMonth() + 1, 2));
format = format.replace(/d/g, this.zeroFill(dateObj.getDate(), 2));
format = format.replace(/H/g, this.zeroFill(dateObj.getHours(), 2));
format = format.replace(/i/g, this.zeroFill(dateObj.getMinutes(), 2));
format = format.replace(/s/g, this.zeroFill(dateObj.getSeconds(), 2));
return format;
},
date2string(params, format) {
if (params === null) {
return params;
}
if (typeof format === "undefined") {
format = "Y-m-d H:i:s";
}
if (params instanceof Date) {
params = this.formatDate(format, params);
} else if (this.isJson(params)) {
for (let key in params) {
if (!params.hasOwnProperty(key)) continue;
params[key] = this.date2string(params[key], format);
}
} else if (this.isArray(params)) {
params.forEach((val, index) => {
params[index] = this.date2string(val, format);
});
}
return params;
},
setStorage(key, value) {
return this.storage(key, value);
},
getStorage(key, def = null) {
let value = this.storage(key);
return value || def;
},
getStorageString(key, def = '') {
let value = this.storage(key);
return typeof value === "string" || typeof value === "number" ? value : def;
},
getStorageInt(key, def = 0) {
let value = this.storage(key);
return typeof value === "number" ? value : def;
},
getStorageBoolean(key, def = false) {
let value = this.storage(key);
return typeof value === "boolean" ? value : def;
},
getStorageArray(key, def = []) {
let value = this.storage(key);
return this.isArray(value) ? value : def;
},
getStorageJson(key, def = {}) {
let value = this.storage(key);
return this.isJson(value) ? value : def;
},
isArray(obj) {
return typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == '[object array]' && typeof obj.length == "number";
},
isJson(obj) {
return typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && typeof obj.length == "undefined";
},
inArray(key, array) {
if (!this.isArray(array)) {
return false;
}
return array.includes(key);
},
storage(key, value) {
if (!key) {
return;
}
let keyName = '__state__';
if (key.substring(0, 5) === 'cache') {
keyName = '__state:' + key + '__';
}
if (typeof value === 'undefined') {
return this.loadFromlLocal(key, '', keyName);
} else {
this.savaToLocal(key, value, keyName);
}
},
savaToLocal(key, value, keyName) {
try {
if (typeof keyName === 'undefined') keyName = '__seller__';
let seller = window.localStorage[keyName];
if (!seller) {
seller = {};
} else {
seller = JSON.parse(seller);
}
seller[key] = value;
window.localStorage[keyName] = JSON.stringify(seller);
} catch (e) {
}
},
loadFromlLocal(key, def, keyName) {
try {
if (typeof keyName === 'undefined') keyName = '__seller__';
let seller = window.localStorage[keyName];
if (!seller) {
return def;
}
seller = JSON.parse(seller);
if (!seller || typeof seller[key] === 'undefined') {
return def;
}
return seller[key];
} catch (e) {
return def;
}
},
runNum(str, fixed) {
let _s = Number(str);
if (_s + "" === "NaN") {
_s = 0;
}
if (/^[0-9]*[1-9][0-9]*$/.test(fixed)) {
_s = _s.toFixed(fixed);
let rs = _s.indexOf('.');
if (rs < 0) {
_s += ".";
for (let i = 0; i < fixed; i++) {
_s += "0";
}
}
}
return _s;
},
cloneJSON(myObj) {
if (typeof (myObj) !== 'object') return myObj;
if (myObj === null) return myObj;
return this.jsonParse(this.jsonStringify(myObj))
},
jsonParse(str, defaultVal) {
if (str === null) {
return defaultVal ? defaultVal : {};
}
if (typeof str === "object") {
return str;
}
try {
return JSON.parse(str.replace(/\n/g, "\\n").replace(/\r/g, "\\r"));
} catch (e) {
return defaultVal ? defaultVal : {};
}
},
jsonStringify(json, defaultVal) {
if (typeof json !== 'object') {
return json;
}
try {
return JSON.stringify(json);
} catch (e) {
return defaultVal ? defaultVal : "";
}
},
projectParameterTemplate(project_id) {
return {
project_id,
card: true,
cardInit: false,
chat: false,
showMy: true,
showHelp: true,
showUndone: true,
showCompleted: false,
completedTask: false,
}
}
};
// 方法类
const state = { method };
const state = {};
// 浏览器宽度≤768返回true
state.windowMax768 = window.innerWidth <= 768;
@ -274,19 +10,19 @@ state.cacheDrawerOverlay = [];
// User
state.cacheUserActive = {};
state.cacheUserWait = [];
state.cacheUserBasic = state.method.getStorageArray("cacheUserBasic");
state.cacheUserBasic = $A.getStorageArray("cacheUserBasic");
// Dialog
state.cacheDialogs = state.method.getStorageArray("cacheDialogs");
state.cacheDialogs = $A.getStorageArray("cacheDialogs");
// Project
state.cacheProjects = state.method.getStorageArray("cacheProjects");
state.cacheColumns = state.method.getStorageArray("cacheColumns");
state.cacheTasks = state.method.getStorageArray("cacheTasks");
state.cacheProjectParameter = state.method.getStorageArray("cacheProjectParameter");
state.cacheProjects = $A.getStorageArray("cacheProjects");
state.cacheColumns = $A.getStorageArray("cacheColumns");
state.cacheTasks = $A.getStorageArray("cacheTasks");
state.cacheProjectParameter = $A.getStorageArray("cacheProjectParameter");
// ServerUrl
state.cacheServerUrl = state.method.getStorageString("cacheServerUrl")
state.cacheServerUrl = $A.getStorageString("cacheServerUrl")
if (state.cacheServerUrl && window.systemInformation) {
window.systemInformation.apiUrl = state.cacheServerUrl;
}
@ -305,10 +41,10 @@ state.wsReadTimeout = null;
state.wsReadWaitList = [];
// 会员信息
state.userInfo = state.method.getStorageJson("userInfo");
state.userId = state.userInfo.userid = state.method.runNum(state.userInfo.userid);
state.userInfo = $A.getStorageJson("userInfo");
state.userId = state.userInfo.userid = $A.runNum(state.userInfo.userid);
state.userToken = state.userInfo.token;
state.userIsAdmin = state.method.inArray("admin", state.userInfo.identity);
state.userIsAdmin = $A.inArray("admin", state.userInfo.identity);
state.userOnline = {};
// 会话聊天