UNPKG

3.49 kBJavaScriptView Raw
1/**
2 * Module : Kero webpack entry row index
3 * Author : liuyk(liuyuekai@yonyou.com)
4 * Date : 2016-08-09 15:24:46
5 */
6
7import {
8 Events
9} from './indexEvents';
10
11
12import {
13 rowDataFunObj
14} from './row-data';
15
16import {
17 rowGetDataFunObj
18} from './row-getData';
19
20import {
21 rowGetMetaFunObj
22} from './row-getMeta';
23
24import {
25 rowGetSimpleDataFunObj
26} from './row-getSimpleData';
27
28import {
29 rowInitFunObj
30} from './row-init';
31
32import {
33 rowMetaFunObj
34} from './row-meta';
35
36import {
37 rowRefFunObj
38} from './row-ref';
39
40import {
41 rowRowSelectFunObj
42} from './row-rowSelect';
43
44import {
45 rowSimpleDataFunObj
46} from './row-simpleData';
47
48import {
49 rowUtilFunObj
50} from './row-util';
51
52
53/**
54 * Row
55 * @namespace
56 * @description 前端数据模型行对象
57 */
58
59class Row extends Events {
60 constructor(options) {
61 super();
62 var self = this;
63 /**
64 * 当前行的唯一标识
65 * @type {string}
66 */
67 this.rowId = options['id'] || Row.getRandomRowId()
68 /**
69 * 当前行的状态
70 * Row.STATUS.NORMAL('nrm') :前后端都存在并且保持一致
71 * Row.STATUS.UPDATE('upd') :前后端都存在并且前端进行了修改
72 * Row.STATUS.NEW('new') :后端不存在,前端存在的数据
73 * Row.STATUS.DELETE('del') :后端请求返回的状态,前端判断为此状态则将数据删除
74 * Row.STATUS.FALSE_DELETE('fdel') :后端存在,前端不存在的数据
75 * @type {string}
76 * @default Row.STATUS.NEW
77 */
78 this.status = Row.STATUS.NEW
79 /**
80 * 当前行对应的DataTable对象
81 * @type {u.DataTable}
82 */
83 this.parent = options['parent']
84 // 当前行的数据信息
85 this.data = {}
86 // 存储meta改变信息
87 this.metaChange = {} //ko.observable(1)
88 // 存储valuecahnge改变信息
89 this.valueChange = {};
90 // 监听当前行改变
91 this.currentRowChange = ko.observable(1);
92 // 监听当前行是否选中
93 this.selected = ko.pureComputed({
94 read: function() {
95 var index = this.parent.getRowIndex(this);
96 var selectindices = this.parent.getSelectedIndices();
97 return selectindices.indexOf(index) != -1;
98 },
99 owner: this
100
101 })
102 // 监听当前行是否为focus
103 this.focused = ko.pureComputed({
104 read: function() {
105 var index = this.parent.getRowIndex(this);
106 var focusIndex = this.parent.getFocusIndex()
107 return focusIndex == index;
108 },
109 owner: this
110
111 })
112 this.init();
113 }
114}
115const RowProto = Row.prototype;
116Object.assign(RowProto, rowDataFunObj);
117Object.assign(RowProto, rowGetDataFunObj);
118Object.assign(RowProto, rowGetMetaFunObj);
119Object.assign(RowProto, rowGetSimpleDataFunObj);
120Object.assign(RowProto, rowInitFunObj);
121Object.assign(RowProto, rowMetaFunObj);
122Object.assign(RowProto, rowRefFunObj);
123Object.assign(RowProto, rowRowSelectFunObj);
124Object.assign(RowProto, rowSimpleDataFunObj);
125Object.assign(RowProto, rowUtilFunObj);
126
127Row.STATUS = {
128 NORMAL: 'nrm',
129 UPDATE: 'upd',
130 NEW: 'new',
131 DELETE: 'del',
132 FALSE_DELETE: 'fdel'
133}
134
135/*
136 * 生成随机行id
137 * @private
138 */
139Row.getRandomRowId = function() {
140 var _id = setTimeout(function() {})
141 return _id + '';
142};
143
144
145
146export {
147 Row
148}