feat(testing): 增加质检报告独立编辑与详情页面,不再使用弹窗
这个提交包含在:
@@ -1,9 +1,10 @@
|
||||
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
|
||||
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/granary-site'], function ($, undefined, Backend, Table, Form, SiteMixin) {
|
||||
|
||||
var Controller = {
|
||||
index: function () {
|
||||
var vue = new Vue({
|
||||
el: '#vue',
|
||||
mixins: [SiteMixin],
|
||||
data: {
|
||||
granaryList: [],
|
||||
// 表格当前页数据
|
||||
@@ -22,6 +23,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
listLoading: false,
|
||||
// 搜索字段
|
||||
search: {
|
||||
site: '',
|
||||
startTime: '',
|
||||
endTime: '',
|
||||
keyword: '',
|
||||
@@ -61,6 +63,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
// 刷新页面
|
||||
refreshPage() {
|
||||
this.search = {
|
||||
site: '',
|
||||
startTime: '',
|
||||
endTime: '',
|
||||
keyword: '',
|
||||
@@ -103,6 +106,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
this.listLoading = true;
|
||||
$.getJSON('content/index', {
|
||||
keyword: key,
|
||||
site: this.search.site,
|
||||
type: this.search.type,
|
||||
start_time: this.search.startTime,
|
||||
end_time: this.search.endTime,
|
||||
@@ -263,6 +267,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
add: function () {
|
||||
let vue = new Vue({
|
||||
el: '#vue',
|
||||
mixins: [SiteMixin],
|
||||
data: {
|
||||
granaryList: [],
|
||||
// 字段信息
|
||||
@@ -341,6 +346,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
}
|
||||
|
||||
this.granaryList = data.granaryList;
|
||||
const selected = this.granaryList.find(g => g.id === this.formData.gid);
|
||||
this.formSite = selected ? selected.site : ((this.siteOptions[0] || {}).id || '');
|
||||
} else {
|
||||
this.$message.warning(res.msg);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
define(['jquery', 'bootstrap', 'backend', 'backend/forecast/components'], function ($, undefined, Backend, components) {
|
||||
'use strict';
|
||||
return { index: function () {
|
||||
new Vue({
|
||||
el: '#forecast-app',
|
||||
components: {'forecast-list': components.list, 'forecast-create': components.create, 'forecast-detail': components.detail},
|
||||
data: { rows: [], granaries: [], total: 0, page: 1, gid: '', site: '', siteOptions: Config.granarySites || [], loading: false, saving: false, creating: false, viewing: false, selected: null, loadSequence: 0 },
|
||||
created: function () { this.load(); },
|
||||
methods: {
|
||||
api: function (action, data, method) {
|
||||
var self = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
$.ajax({url: 'forecast/' + action, type: method || 'GET', data: data || {}, dataType: 'json', timeout: 45000,
|
||||
success: function (res) {
|
||||
if (res.code !== 200) { self.$message.error(res.msg || '操作失败,请刷新后重试'); reject(new Error(res.msg)); }
|
||||
else resolve(res);
|
||||
},
|
||||
error: function () { self.$message.error('请求失败或登录已失效,请刷新查看记录后重试'); reject(new Error('request failed')); }
|
||||
});
|
||||
});
|
||||
},
|
||||
load: function () {
|
||||
var self = this, sequence = ++this.loadSequence;
|
||||
this.loading = true;
|
||||
return this.api('index', {gid: this.gid, site: this.site, page: this.page}).then(function (res) {
|
||||
if (sequence !== self.loadSequence) return;
|
||||
self.rows = res.list; self.total = res.total; self.granaries = res.granaries;
|
||||
}).catch(function () {}).then(function () { if (sequence === self.loadSequence) self.loading = false; });
|
||||
},
|
||||
siteChanged: function () { this.gid = ''; this.page = 1; this.load(); },
|
||||
filterChanged: function () { this.page = 1; this.load(); },
|
||||
changePage: function (page) { this.page = page; this.load(); },
|
||||
newRecord: function () { this.creating = true; },
|
||||
closeCreate: function (done) { if (!this.saving) { this.creating = false; if (typeof done === 'function') done(); } },
|
||||
closeDetail: function (done) {
|
||||
var self = this;
|
||||
if (this.saving) return;
|
||||
this.$refs.detail.confirmDiscard().then(function () { self.viewing = false; if (typeof done === 'function') done(); }).catch(function () {});
|
||||
},
|
||||
openRecord: function (id) {
|
||||
var self = this;
|
||||
this.api('detail', {id: id}).then(function (res) { self.selected = res.data; self.viewing = true; }).catch(function () {});
|
||||
},
|
||||
write: function (action, data, callback) {
|
||||
if (this.saving) return;
|
||||
var self = this;
|
||||
this.saving = true;
|
||||
this.api(action, data, 'POST').then(function (res) {
|
||||
self.selected = res.data;
|
||||
if (action !== 'actual' && res.data.status === 'failed') self.$message.warning('温湿度已保存,算法暂不可用,可稍后重新生成');
|
||||
else self.$message.success(action === 'actual' ? '实测值已保存' : res.data.status === 'ready' ? '预测已生成并保存' : '记录已保存');
|
||||
if (callback) callback();
|
||||
self.load();
|
||||
}).catch(function () {}).then(function () { self.saving = false; });
|
||||
},
|
||||
createRecord: function (form) {
|
||||
var self = this;
|
||||
this.write('add', form, function () { self.creating = false; self.viewing = true; });
|
||||
},
|
||||
saveActual: function (form) { this.write('actual', form); },
|
||||
retry: function (id) {
|
||||
var self = this;
|
||||
this.$refs.detail.confirmDiscard().then(function () { self.write('retry', {id: id}); }).catch(function () {});
|
||||
}
|
||||
}
|
||||
});
|
||||
} };
|
||||
});
|
||||
@@ -0,0 +1,204 @@
|
||||
define([], function () {
|
||||
'use strict';
|
||||
function today() {
|
||||
var d = new Date();
|
||||
return [d.getFullYear(), String(d.getMonth() + 1).padStart(2, '0'), String(d.getDate()).padStart(2, '0')].join('-');
|
||||
}
|
||||
function number(v) { return v === null || v === undefined || v === '' ? '—' : String(Number(v)); }
|
||||
function signed(v) { return v === null ? '—' : (v > 0 ? '+' : '') + Number(v); }
|
||||
function requestKey() {
|
||||
var bytes = new Uint8Array(16);
|
||||
window.crypto.getRandomValues(bytes);
|
||||
return Array.from(bytes, function (n) { return n.toString(16).padStart(2, '0'); }).join('');
|
||||
}
|
||||
var dateOptions = { disabledDate: function (date) { return date.getTime() > Date.now() || date.getFullYear() < 2000; } };
|
||||
|
||||
/**
|
||||
* 中储粮《粮油储藏技术规范》GB/T 29890 标准工况模板
|
||||
*/
|
||||
var PRESETS = {
|
||||
quasi_low: {
|
||||
key: 'quasi_low',
|
||||
name: '准低温储粮推荐工况',
|
||||
tag: '准低温 (≤20℃)',
|
||||
type: 'primary',
|
||||
desc: '仓温≤20℃,绿色控温优选温区,延缓陈化',
|
||||
tm_i: 18.5,
|
||||
hm_i: 70.0,
|
||||
tm_o: 32.0,
|
||||
hm_o: 55.0
|
||||
},
|
||||
low: {
|
||||
key: 'low',
|
||||
name: '低温储粮标准工况',
|
||||
tag: '低温 (≤15℃)',
|
||||
type: 'success',
|
||||
desc: '仓温≤15℃,抑虫抑菌保鲜,高标准储粮',
|
||||
tm_i: 14.0,
|
||||
hm_i: 65.0,
|
||||
tm_o: 28.0,
|
||||
hm_o: 60.0
|
||||
},
|
||||
normal: {
|
||||
key: 'normal',
|
||||
name: '常温储粮常规工况',
|
||||
tag: '常温 (≤25℃)',
|
||||
type: 'info',
|
||||
desc: '仓温≤25℃,常规安全储粮受控温区',
|
||||
tm_i: 22.0,
|
||||
hm_i: 72.0,
|
||||
tm_o: 32.0,
|
||||
hm_o: 55.0
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 依据中储粮温控标准研判仓内温湿度合规状态
|
||||
*/
|
||||
function evaluateTemp(tm_i, hm_i) {
|
||||
if (tm_i === '' || tm_i === null || tm_i === undefined || !Number.isFinite(Number(tm_i))) {
|
||||
return { grade: 'unknown', label: '待设置', tagType: 'info', isHigh: false, hint: '请设置仓内温度' };
|
||||
}
|
||||
var t = Number(tm_i);
|
||||
if (t <= 15.0) {
|
||||
return { grade: 'low', label: '低温储粮', tagType: 'success', isHigh: false, hint: '达到低温储粮标准 (≤15℃,抑虫控酶,保质保鲜最优)' };
|
||||
}
|
||||
if (t <= 20.0) {
|
||||
return { grade: 'quasi_low', label: '准低温储粮', tagType: 'primary', isHigh: false, hint: '达到中储粮准低温推荐标准 (≤20℃,绿色控温优选温区)' };
|
||||
}
|
||||
if (t <= 25.0) {
|
||||
return { grade: 'normal', label: '常温储粮', tagType: 'info', isHigh: false, hint: '处于常温储粮安全控温范围 (≤25℃)' };
|
||||
}
|
||||
return { grade: 'high_warn', label: '高温超标预警', tagType: 'danger', isHigh: true, hint: '⚠️ 超过25℃中储粮控温安全线(当前' + t + '℃),高温易致发热霉变与虫害,请及时开启空调或通风降温!' };
|
||||
}
|
||||
|
||||
return {
|
||||
list: {
|
||||
template: '#forecast-list-template', props: ['rows', 'loading'],
|
||||
methods: {
|
||||
number: number,
|
||||
status: function (s) { return {pending: '待生成', processing: '生成中', ready: '已生成', failed: '生成失败,可重试'}[s] || s; },
|
||||
evalTemp: evaluateTemp
|
||||
}
|
||||
},
|
||||
create: {
|
||||
template: '#forecast-create-template', props: ['granaries', 'busy', 'siteDefaultEnv'],
|
||||
data: function () { return {
|
||||
form: {gid: '', observed_date: today(), horizons: [7, 15, 30, 60], tm_i: 18.5, hm_i: 70.0, tm_o: 32.0, hm_o: 55.0, request_key: requestKey()},
|
||||
dateOptions: dateOptions,
|
||||
presets: PRESETS,
|
||||
selectedPresetKey: 'quasi_low',
|
||||
fields: [
|
||||
{key: 'tm_i', label: '仓内温度', unit: '℃', min: -50, max: 80, step: 0.1, placeholder: '例:18.5'},
|
||||
{key: 'hm_i', label: '仓内相对湿度', unit: '%', min: 0, max: 100, step: 0.1, placeholder: '例:70.0'},
|
||||
{key: 'tm_o', label: '仓外温度', unit: '℃', min: -50, max: 80, step: 0.1, placeholder: '例:32.0'},
|
||||
{key: 'hm_o', label: '仓外相对湿度', unit: '%', min: 0, max: 100, step: 0.1, placeholder: '例:55.0'}
|
||||
]
|
||||
}; },
|
||||
computed: {
|
||||
tempStatus: function () {
|
||||
return evaluateTemp(this.form.tm_i, this.form.hm_i);
|
||||
},
|
||||
selectedGranary: function () {
|
||||
var gid = this.form.gid;
|
||||
return this.granaries.find(function (g) { return String(g.id) === String(gid); }) || null;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'form.gid': function (newGid) {
|
||||
if (!newGid) return;
|
||||
this.onGranaryChange(newGid);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
applyPreset: function (key) {
|
||||
var p = this.presets[key];
|
||||
if (!p) return;
|
||||
this.selectedPresetKey = key;
|
||||
this.form.tm_i = p.tm_i;
|
||||
this.form.hm_i = p.hm_i;
|
||||
this.form.tm_o = p.tm_o;
|
||||
this.form.hm_o = p.hm_o;
|
||||
this..success('已套用【' + p.name + '】规范温湿度');
|
||||
},
|
||||
onGranaryChange: function (gid) {
|
||||
var granary = this.granaries.find(function (g) { return String(g.id) === String(gid); });
|
||||
if (!granary) return;
|
||||
// 若仓库自带最近一次历史环境记录 last_env,则智能推荐带出
|
||||
if (granary.last_env && granary.last_env.tm_i !== undefined && granary.last_env.tm_i !== '') {
|
||||
this.form.tm_i = Number(granary.last_env.tm_i);
|
||||
this.form.hm_i = Number(granary.last_env.hm_i);
|
||||
this.form.tm_o = Number(granary.last_env.tm_o);
|
||||
this.form.hm_o = Number(granary.last_env.hm_o);
|
||||
this.selectedPresetKey = '';
|
||||
this..info('已自动读取【' + granary.name + '】最近一次温湿度记录');
|
||||
} else if (this.form.tm_i === '' || this.form.tm_i === undefined) {
|
||||
this.applyPreset('quasi_low');
|
||||
}
|
||||
},
|
||||
submit: function () {
|
||||
if (!this.form.gid || !this.form.observed_date || !this.form.horizons.length) return this..warning('请选择仓库、采集日期和预测周期');
|
||||
for (var i = 0; i < this.fields.length; i++) {
|
||||
var f = this.fields[i], v = this.form[f.key];
|
||||
if (v === '' || !Number.isFinite(Number(v)) || Number(v) < f.min || Number(v) > f.max) return this..warning('请填写有效的' + f.label + '(' + f.min + '~' + f.max + ')');
|
||||
}
|
||||
this.('submit', JSON.parse(JSON.stringify(this.form)));
|
||||
}
|
||||
}
|
||||
},
|
||||
detail: {
|
||||
template: '#forecast-detail-template', props: ['record', 'busy'],
|
||||
data: function () { return { active: '', actualDate: '', actual: {}, baseline: '', dateOptions: dateOptions }; },
|
||||
computed: {
|
||||
point: function () { var id = this.active; return this.record.points.find(function (p) { return String(p.id) === id; }); },
|
||||
dirty: function () { return this.baseline !== this.snapshot(); },
|
||||
comparison: function () {
|
||||
if (!this.point) return [];
|
||||
var actual = this.actual;
|
||||
return this.point.rows.map(function (row) {
|
||||
var value = actual[row.key], val = value === '' || value === null || value === undefined || !Number.isFinite(Number(value)) ? null : Number(value);
|
||||
var delta = val !== null && row.predicted !== null ? Number((val - row.predicted).toFixed(4)) : null;
|
||||
return Object.assign({}, row, {delta: delta, percent: delta !== null && row.predicted !== 0 ? Number((delta / Math.abs(row.predicted) * 100).toFixed(2)) : null});
|
||||
});
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
active: function () { this.reset(); },
|
||||
record: { immediate: true, handler: function () {
|
||||
if (!this.record.points.some(function (p) { return String(p.id) === this.active; }, this)) this.active = String(this.record.points[0].id);
|
||||
this.reset();
|
||||
} }
|
||||
},
|
||||
methods: {
|
||||
number: number, signed: signed,
|
||||
snapshot: function () { return JSON.stringify([this.actualDate, this.actual]); },
|
||||
reset: function () {
|
||||
var point = this.point;
|
||||
this.actualDate = point.actual_date || '';
|
||||
var values = {};
|
||||
this.record.metrics.forEach(function (m) { values[m.key] = point.actual[m.key] == null ? '' : String(point.actual[m.key]); });
|
||||
this.actual = values;
|
||||
this.baseline = this.snapshot();
|
||||
},
|
||||
confirmDiscard: function () {
|
||||
if (this.busy) return Promise.reject();
|
||||
return this.dirty ? this.('当前周期有未保存的实测数据,确定放弃修改?', '未保存的数据', {type: 'warning'}) : Promise.resolve();
|
||||
},
|
||||
beforeLeave: function () {
|
||||
return this.confirmDiscard().then(function () { return true; });
|
||||
},
|
||||
save: function () {
|
||||
var any = false;
|
||||
for (var i = 0; i < this.record.metrics.length; i++) {
|
||||
var m = this.record.metrics[i], v = this.actual[m.key];
|
||||
if (v === '') continue;
|
||||
any = true;
|
||||
if (!Number.isFinite(Number(v)) || Number(v) < 0 || Number(v) > m.max) return this..warning('请填写有效的' + m.name + '实测值');
|
||||
}
|
||||
if (any && !this.actualDate) return this..warning('请选择实际检测日期');
|
||||
this.('save', {point_id: this.point.id, version: this.point.version, actual_date: this.actualDate, actual: Object.assign({}, this.actual)});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
define([], function () {
|
||||
'use strict';
|
||||
return {
|
||||
data: function () { return { siteOptions: Config.granarySites || [], formSite: '' }; },
|
||||
computed: {
|
||||
siteGranaries: function () {
|
||||
var site = this.formSite;
|
||||
return (this.granaryList || []).filter(function (g) { return site && g.site === site; });
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
siteChanged: function () {
|
||||
this.currentPage = 1;
|
||||
this.search.gid = '';
|
||||
this.search.rid = '';
|
||||
this.multipleSelection = [];
|
||||
this.loadData(this.search.keyword, 1, this.pageSize, this.search.sort);
|
||||
},
|
||||
formSiteChanged: function () { this.formData.gid = ''; },
|
||||
granaryLabel: function (g) { return g.label || ((g.site === 'xishui' ? '习水库' : '遵义中心库') + ' · ' + g.name); }
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -1,9 +1,10 @@
|
||||
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
|
||||
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/granary-site'], function ($, undefined, Backend, Table, Form, SiteMixin) {
|
||||
|
||||
var Controller = {
|
||||
index: function () {
|
||||
var vue = new Vue({
|
||||
el: '#vue',
|
||||
mixins: [SiteMixin],
|
||||
data: {
|
||||
contentType: 'one',
|
||||
varietiesType: 'one',
|
||||
@@ -212,6 +213,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
}],
|
||||
// 搜索字段
|
||||
search: {
|
||||
site: '',
|
||||
startTime: '',
|
||||
endTime: '',
|
||||
keyword: '',
|
||||
@@ -239,6 +241,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
message: '请您输入粮仓名称',
|
||||
trigger: 'blur'
|
||||
}],
|
||||
site: [{
|
||||
required: true, message: '请选择所属库区', trigger: 'change'
|
||||
}],
|
||||
storage: [{
|
||||
required: true,
|
||||
message: '请您输入仓库储存点',
|
||||
@@ -263,6 +268,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort);
|
||||
},
|
||||
methods: {
|
||||
changeSite(site) {
|
||||
const selected = this.siteOptions.find(s => s.id === site);
|
||||
this.formData.storage = selected ? selected.storage : '';
|
||||
this.formData.screenPosition = '';
|
||||
this.changeGranaryType(site === 'xishui' ? 3 : 2);
|
||||
},
|
||||
// 直达中心库大屏
|
||||
openCenterScreen() {
|
||||
window.open('/screen/index.html', '_blank');
|
||||
@@ -274,6 +285,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
// 刷新页面
|
||||
refreshPage() {
|
||||
this.search = {
|
||||
site: '',
|
||||
startTime: '',
|
||||
endTime: '',
|
||||
keyword: '',
|
||||
@@ -291,7 +303,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
if (isNaN(num)) return;
|
||||
this.formData.num = num;
|
||||
if (this.title === '添加' && this.formData.granary_type !== 3) {
|
||||
this.formData.granary_type = num > 18 ? 2 : 1;
|
||||
this.formData.granary_type = this.formData.site === 'xishui' ? (num <= 8 ? 3 : 2) : (num > 18 ? 2 : 1);
|
||||
this.changeGranaryType(this.formData.granary_type);
|
||||
}
|
||||
},
|
||||
@@ -397,15 +409,15 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
id: 0,
|
||||
name: '',
|
||||
image: '',
|
||||
storage: '成都直属库有限公司本部',
|
||||
site: this.search.site || (this.siteOptions[0] || {}).id || '',
|
||||
storage: '',
|
||||
num: '',
|
||||
screenPosition: '',
|
||||
granary_type: 1,
|
||||
varieties: '菜籽油',
|
||||
content: []
|
||||
};
|
||||
this.contentType = 'one';
|
||||
this.varietiesType = 'one';
|
||||
this.changeSite(this.formData.site);
|
||||
} else {
|
||||
this.title = '编辑';
|
||||
let isPreset = ['菜籽油', '大豆油', '稻谷', '小麦', '玉米'].indexOf(item.varieties) !== -1;
|
||||
@@ -416,6 +428,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
image: item.image,
|
||||
site: item.site,
|
||||
storage: item.storage,
|
||||
num: item.num,
|
||||
screenPosition: (item.content || {}).screenPosition || '',
|
||||
@@ -433,7 +446,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
this.contentType = 'two';
|
||||
}
|
||||
|
||||
if (this.formData.granary_type == 1) {
|
||||
if (Number(this.formData.granary_type) === 1) {
|
||||
this.varietiesType = 'one';
|
||||
} else {
|
||||
this.varietiesType = 'two';
|
||||
@@ -463,6 +476,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
this.listLoading = true;
|
||||
$.getJSON('granary/index', {
|
||||
keyword: key,
|
||||
site: this.search.site,
|
||||
type: this.search.type,
|
||||
start_time: this.search.startTime,
|
||||
end_time: this.search.endTime,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
|
||||
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/granary-site'], function ($, undefined, Backend, Table, Form, SiteMixin) {
|
||||
|
||||
var Controller = {
|
||||
index: function () {
|
||||
let vue = new Vue({
|
||||
el: '#vue',
|
||||
mixins: [SiteMixin],
|
||||
data: {
|
||||
typeName: '',
|
||||
detail: {
|
||||
@@ -62,6 +63,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
listLoading: false,
|
||||
// 搜索字段
|
||||
search: {
|
||||
site: '',
|
||||
startTime: '',
|
||||
endTime: '',
|
||||
keyword: '',
|
||||
@@ -115,9 +117,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort);
|
||||
},
|
||||
methods: {
|
||||
isRuleNumber(value) {
|
||||
return (typeof value === 'string' || typeof value === 'number')
|
||||
&& /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/.test(String(value).trim())
|
||||
&& Number.isFinite(Number(value));
|
||||
},
|
||||
isNumericRule(item) {
|
||||
return [item.warning, item.alert].every(value =>
|
||||
value !== null && value !== undefined && String(value).trim() !== '' && Number.isFinite(Number(value)));
|
||||
return [item.warning, item.alert].every(value => this.isRuleNumber(value));
|
||||
},
|
||||
ruleDirection(item) {
|
||||
return item.direction === 'upper' || item.direction === 'lower' ? item.direction
|
||||
@@ -140,7 +146,14 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
: [`当前值 ≥ ${w}`, `${a} ≤ 当前值 < ${w}`, `当前值 < ${a}`];
|
||||
},
|
||||
ruleError(item) {
|
||||
const expectsNumeric = item.rule_numeric === true || Number(item.is_number) === 1
|
||||
|| this.isRuleNumber(item.warning) || this.isRuleNumber(item.alert);
|
||||
if (expectsNumeric && !this.isNumericRule(item)) return '预警值和警告值必须都是有限数字';
|
||||
if (!this.isNumericRule(item)) return '';
|
||||
if (!this.isRuleNumber(item.val)
|
||||
&& !/^(?:\/|--?|未检测|未提供|暂无|未检出|未检出\s*ND|ND)$/i.test(String(item.val ?? '').trim())) {
|
||||
return '检测值必须是有限数字,缺测可填 /';
|
||||
}
|
||||
const upper = this.ruleDirection(item) === 'upper';
|
||||
return (upper && Number(item.warning) > Number(item.alert)) || (!upper && Number(item.warning) < Number(item.alert))
|
||||
? (upper ? '越小越好指标要求:预警值 ≤ 警告值(高值预警)' : '越大越好指标要求:预警值 ≥ 警告值(低值预警)') : '';
|
||||
@@ -148,6 +161,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
// 刷新页面
|
||||
refreshPage() {
|
||||
this.search = {
|
||||
site: '',
|
||||
startTime: '',
|
||||
endTime: '',
|
||||
keyword: '',
|
||||
@@ -164,15 +178,37 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
let list = this.granaryList;
|
||||
let item = list.find(v => v.id === e);
|
||||
|
||||
if (!item) return;
|
||||
this.typeName = item.varieties;
|
||||
this.formData.type = item.type;
|
||||
},
|
||||
handelIsNumber(index, val) {
|
||||
this.typeList[this.formData.type]['content'][index].is_number = val;
|
||||
},
|
||||
openPage(url, title) {
|
||||
if (typeof top !== 'undefined' && top && top.Backend && top.Backend.api && typeof top.Backend.api.addtabs === 'function') {
|
||||
top.Backend.api.addtabs(url, title);
|
||||
} else if (typeof Backend !== 'undefined' && Backend && Backend.api && typeof Backend.api.addtabs === 'function') {
|
||||
Backend.api.addtabs(url, title);
|
||||
} else if (typeof window !== 'undefined' && window.location) {
|
||||
window.location.href = url;
|
||||
}
|
||||
},
|
||||
openAddPage() {
|
||||
this.openPage('testing/add', '添加检测报告');
|
||||
},
|
||||
openEditPage(item) {
|
||||
var id = typeof item === 'object' ? item.id : item;
|
||||
var name = (item && item.granary && item.granary.name) ? ' - ' + item.granary.name : '';
|
||||
this.openPage('testing/edit?ids=' + id, '编辑检测报告' + name);
|
||||
},
|
||||
openDetailPage(item) {
|
||||
var id = typeof item === 'object' ? item.id : item;
|
||||
var name = (item && item.granary && item.granary.name) ? ' - ' + item.granary.name : '';
|
||||
this.openPage('testing/detail?ids=' + id, '检测报告详情' + name);
|
||||
},
|
||||
openDialogDetail(detail) {
|
||||
this.detail = detail;
|
||||
this.detailDialog = true;
|
||||
this.openDetailPage(detail);
|
||||
},
|
||||
handleClearSelect(field) {
|
||||
// 重新加载
|
||||
@@ -261,13 +297,14 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
})
|
||||
});
|
||||
},
|
||||
// 添加/编辑
|
||||
// 添加/编辑(兼容原有状态准备)
|
||||
openAddDialog(type, item) {
|
||||
this.addDialog = true;
|
||||
this.typeList = JSON.parse(JSON.stringify(this.newTypeList));
|
||||
|
||||
if (type === 'add') {
|
||||
this.title = '添加';
|
||||
this.formSite = this.search.site || (this.siteOptions[0] || {}).id || '';
|
||||
this.formData = {
|
||||
id: 0,
|
||||
gid: '',
|
||||
@@ -279,6 +316,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
};
|
||||
} else {
|
||||
this.title = '编辑';
|
||||
this.formSite = item.granary.site;
|
||||
this.formData = {
|
||||
id: item.id,
|
||||
gid: item.gid,
|
||||
@@ -292,6 +330,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
this.typeName = item.granary.varieties;
|
||||
this.typeList[item.type]['content'] = JSON.parse(JSON.stringify(item.testing_params));
|
||||
}
|
||||
for (const group of Object.values(this.typeList)) {
|
||||
for (const row of group.content || []) {
|
||||
this.$set(row, 'rule_numeric', this.isNumericRule(row));
|
||||
}
|
||||
}
|
||||
},
|
||||
handleSort(item) {
|
||||
// 提交
|
||||
@@ -325,6 +368,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
this.listLoading = true;
|
||||
$.getJSON('testing/index', {
|
||||
keyword: key,
|
||||
site: this.search.site,
|
||||
type: this.search.type,
|
||||
gid: this.search.gid,
|
||||
date: this.search.date,
|
||||
|
||||
在新工单中引用
屏蔽一个用户