JEditableTable.vue 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372
  1. <!-- JEditableTable -->
  2. <!-- @version 1.5.0 -->
  3. <!-- @author sjlei -->
  4. <template>
  5. <a-spin :spinning="loading">
  6. <a-row type="flex">
  7. <a-col>
  8. <slot name="buttonBefore" :target="getVM()" />
  9. </a-col>
  10. <a-col>
  11. <!-- 操作按钮 -->
  12. <div v-if="actionButton" class="action-button">
  13. <a-button type="primary" icon="plus" @click="handleClickAdd" :disabled="disabled">插入行</a-button>
  14. <span class="gap"></span>
  15. <template v-if="selectedRowIds.length > 0">
  16. <a-popconfirm :title="`确定要移除这 ${selectedRowIds.length} 项吗?`" @confirm="handleConfirmDelete">
  17. <a-button type="primary" icon="minus" :disabled="disabled">移除行</a-button>
  18. <span class="gap"></span>
  19. </a-popconfirm>
  20. <template v-if="showClearSelectButton">
  21. <a-button icon="delete" @click="handleClickClearSelection">清空选择</a-button>
  22. <span class="gap"></span>
  23. </template>
  24. </template>
  25. </div>
  26. </a-col>
  27. <a-col>
  28. <slot name="buttonAfter" :target="getVM()" />
  29. </a-col>
  30. </a-row>
  31. <slot name="actionButtonAfter" :target="getVM()" />
  32. <div :id="`${caseId}inputTable`" class="input-table" :style="{ 'min-width': minWidth + 'px' }">
  33. <!-- 渲染表头 -->
  34. <div class="thead" ref="thead">
  35. <div class="tr" :style="{ width: this.realTrWidth }">
  36. <!-- 左侧固定td -->
  37. <div v-if="dragSort" class="td td-ds" :style="style.tdLeftDs">
  38. <span></span>
  39. </div>
  40. <div v-if="dragSortAndNumber" class="td td-ds" :style="style.tdLeftDs">
  41. <span>#</span>
  42. </div>
  43. <div v-if="rowNumber" class="td td-num" :style="style.tdLeft">
  44. <span>#</span>
  45. </div>
  46. <div v-if="rowSelection" class="td td-cb" :style="style.tdLeft">
  47. <!--:indeterminate="true"-->
  48. <a-checkbox
  49. :checked="getSelectAll"
  50. :indeterminate="getSelectIndeterminate"
  51. @change="handleChangeCheckedAll"
  52. />
  53. </div>
  54. <!-- 右侧动态生成td 这里是title -->
  55. <template v-for="col in columns" v-if="col.type !== formTypes.hidden">
  56. <div class="td" :key="col.key" :style="buildTdStyle(col)">
  57. <span style="padding: 0 5px">
  58. {{ col.title }}
  59. <slot name="depotBatchSet" v-if="col.key === 'depotId'" :target="getVM()" />
  60. </span>
  61. </div>
  62. </template>
  63. </div>
  64. </div>
  65. <div class="scroll-view" ref="scrollView" :style="{ 'max-height': maxHeight + 'px' }">
  66. <!-- 渲染主体 body -->
  67. <div :id="`${caseId}tbody`" class="tbody" :style="tbodyStyle">
  68. <!-- 扩展高度 -->
  69. <div class="tr-expand" :style="`height:${getExpandHeight}px; z-index:${loading ? '11' : '9'};`"></div>
  70. <!-- 无数据时显示 -->
  71. <div v-if="rows.length === 0" class="tr-nodata">
  72. <span>暂无数据</span>
  73. </div>
  74. <!-- v-model="rows"-->
  75. <draggable :value="rows" handle=".td-ds-icons" @start="handleDragMoveStart" @end="handleDragMoveEnd">
  76. <!-- 动态生成tr -->
  77. <template v-for="(row, rowIndex) in rows">
  78. <!-- tr 如果超出200条,则只加载可见的和预加载的总共十条数据 -->
  79. <div
  80. v-if="
  81. rows.length <= 200 ||
  82. (rows.length > 200 &&
  83. rowIndex >= parseInt(`${(scrollTop - rowHeight) / rowHeight}`) &&
  84. parseInt(`${scrollTop / rowHeight}`) + 9 > rowIndex)
  85. "
  86. :id="`${caseId}tbody-tr-${rowIndex}`"
  87. :data-idx="rowIndex"
  88. class="tr"
  89. :class="selectedRowIds.indexOf(row.id) !== -1 ? 'tr-checked' : ''"
  90. :style="buildTrStyle(rowIndex)"
  91. :key="row.id"
  92. >
  93. <!-- 左侧固定td -->
  94. <div v-if="dragSort" class="td td-ds" :style="style.tdLeftDs">
  95. <a-dropdown :trigger="['click']" :getPopupContainer="getParentContainer">
  96. <div class="td-ds-icons">
  97. <a-icon type="align-left" />
  98. <a-icon type="align-right" />
  99. </div>
  100. <a-menu slot="overlay">
  101. <a-menu-item key="0" :disabled="rowIndex === 0" @click="_handleRowMoveUp(rowIndex)"
  102. >向上移</a-menu-item
  103. >
  104. <a-menu-item
  105. key="1"
  106. :disabled="rowIndex === rows.length - 1"
  107. @click="_handleRowMoveDown(rowIndex)"
  108. >向下移</a-menu-item
  109. >
  110. <!-- <a-menu-divider/>
  111. <a-menu-item key="3" @click="_handleRowInsertDown(rowIndex)">插入一行</a-menu-item> -->
  112. </a-menu>
  113. </a-dropdown>
  114. </div>
  115. <div v-if="dragSortAndNumber" class="td td-ds" :style="style.tdLeftDs">
  116. <a-dropdown :trigger="['click']" :getPopupContainer="getParentContainer">
  117. <div class="td-ds-icons" title="点击不放可以拖动" style="text-align: center; line-height: 32px">
  118. <span>{{ rowIndex + 1 }}</span>
  119. </div>
  120. <a-menu slot="overlay">
  121. <a-menu-item key="0" :disabled="rowIndex === 0" @click="_handleRowMoveUp(rowIndex)"
  122. >向上移</a-menu-item
  123. >
  124. <a-menu-item
  125. key="1"
  126. :disabled="rowIndex === rows.length - 1"
  127. @click="_handleRowMoveDown(rowIndex)"
  128. >向下移</a-menu-item
  129. >
  130. <!-- <a-menu-divider/>
  131. <a-menu-item key="3" @click="_handleRowInsertDown(rowIndex)">插入一行</a-menu-item> -->
  132. </a-menu>
  133. </a-dropdown>
  134. </div>
  135. <div v-if="rowNumber" class="td td-num" :style="style.tdLeft">
  136. <span>{{ rowIndex + 1 }}</span>
  137. </div>
  138. <div v-if="rowSelection" class="td td-cb" :style="style.tdLeft">
  139. <!-- 此 v-for 只是为了拼接 id 字符串 -->
  140. <template v-for="(id, i) in [`${row.id}`]">
  141. <a-checkbox
  142. :id="id"
  143. :key="i"
  144. :checked="selectedRowIds.indexOf(id) !== -1"
  145. @change="handleChangeLeftCheckbox"
  146. />
  147. </template>
  148. </div>
  149. <!-- 右侧动态生成td 这里是内容区 -->
  150. <div
  151. class="td"
  152. v-for="col in columns"
  153. v-show="col.type !== formTypes.hidden"
  154. :key="col.key"
  155. :style="buildTdStyle(col)"
  156. >
  157. <!-- 此 v-for 只是为了拼接 id 字符串 -->
  158. <template v-for="(id, i) in [`${col.key}${row.id}`]">
  159. <!-- native input -->
  160. <label :key="i" v-if="col.type === formTypes.input || col.type === formTypes.inputNumber">
  161. <a-tooltip
  162. :id="id"
  163. placement="top"
  164. :title="(tooltips[id] || {}).title"
  165. :visible="(tooltips[id] || {}).visible || false"
  166. :autoAdjustOverflow="true"
  167. :getPopupContainer="getParentContainer"
  168. >
  169. <input
  170. :id="id"
  171. :readonly="col.readonly"
  172. :visible="col.visible"
  173. v-bind="buildProps(row, col)"
  174. :data-input-number="col.type === formTypes.inputNumber"
  175. :placeholder="replaceProps(col, col.placeholder)"
  176. @blur="
  177. (e) => {
  178. handleBlurCommono(e.target, rowIndex, row, col)
  179. }
  180. "
  181. @input="
  182. (e) => {
  183. handleInputCommono(e.target, rowIndex, row, col)
  184. }
  185. "
  186. @mouseover="
  187. () => {
  188. handleMouseoverCommono(row, col)
  189. }
  190. "
  191. @mouseout="
  192. () => {
  193. handleMouseoutCommono(row, col)
  194. }
  195. "
  196. />
  197. </a-tooltip>
  198. </label>
  199. <!-- checkbox -->
  200. <template v-else-if="col.type === formTypes.checkbox">
  201. <a-checkbox
  202. :key="i"
  203. :id="id"
  204. v-bind="buildProps(row, col)"
  205. :checked="checkboxValues[id]"
  206. @change="(e) => handleChangeCheckboxCommon(e, row, col)"
  207. />
  208. </template>
  209. <!-- select -->
  210. <template v-else-if="col.type === formTypes.select">
  211. <a-tooltip
  212. :key="i"
  213. :id="id"
  214. placement="top"
  215. :title="(tooltips[id] || {}).title"
  216. :visible="(tooltips[id] || {}).visible || false"
  217. :autoAdjustOverflow="true"
  218. :getPopupContainer="getParentContainer"
  219. >
  220. <span
  221. @mouseover="
  222. () => {
  223. handleMouseoverCommono(row, col)
  224. }
  225. "
  226. @mouseout="
  227. () => {
  228. handleMouseoutCommono(row, col)
  229. }
  230. "
  231. >
  232. <a-select
  233. :id="id"
  234. :key="i"
  235. v-bind="buildProps(row, col)"
  236. style="width: 100%"
  237. :value="getSelectValue(id)"
  238. :options="col.options"
  239. :getPopupContainer="getParentContainer"
  240. :placeholder="replaceProps(col, col.placeholder)"
  241. :filterOption="(i, o) => handleSelectFilterOption(i, o, col)"
  242. @change="(v) => handleChangeSelectCommon(v, id, row, col)"
  243. @search="(v) => handleSearchSelect(v, id, row, col)"
  244. @blur="(v) => handleBlurSearch(v, id, row, col)"
  245. @focus="(v) => handleFocusSearch(v, id, row, col)"
  246. >
  247. <div slot="dropdownRender" slot-scope="menu">
  248. <v-nodes :vnodes="menu" />
  249. <slot name="depotAdd" v-if="col.key === 'depotId'" :target="getVM()" />
  250. <slot name="inOutItemAdd" v-if="col.key === 'inOutItemId'" :target="getVM()" />
  251. </div>
  252. <!-- <template v-for="(opt, optKey) in col.options">
  253. <a-select-option :value="opt.value" :key="optKey">{{ opt.title }}</a-select-option>
  254. </template> -->
  255. </a-select>
  256. </span>
  257. </a-tooltip>
  258. </template>
  259. <!-- date -->
  260. <template v-else-if="col.type === formTypes.date || col.type === formTypes.datetime">
  261. <a-tooltip
  262. :key="i"
  263. :id="id"
  264. placement="top"
  265. :title="(tooltips[id] || {}).title"
  266. :visible="(tooltips[id] || {}).visible || false"
  267. :autoAdjustOverflow="true"
  268. :getPopupContainer="getParentContainer"
  269. >
  270. <span
  271. @mouseover="
  272. () => {
  273. handleMouseoverCommono(row, col)
  274. }
  275. "
  276. @mouseout="
  277. () => {
  278. handleMouseoutCommono(row, col)
  279. }
  280. "
  281. >
  282. <j-date
  283. :id="id"
  284. :key="i"
  285. v-bind="buildProps(row, col)"
  286. style="width: 100%"
  287. :value="jdateValues[id]"
  288. :getCalendarContainer="getParentContainer"
  289. :placeholder="replaceProps(col, col.placeholder)"
  290. :trigger-change="true"
  291. :showTime="col.type === formTypes.datetime"
  292. :dateFormat="col.type === formTypes.date ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'"
  293. allowClear
  294. @change="(v) => handleChangeJDateCommon(v, id, row, col, col.type === formTypes.datetime)"
  295. />
  296. </span>
  297. </a-tooltip>
  298. </template>
  299. <!-- input_pop -->
  300. <template v-else-if="col.type === formTypes.input_pop">
  301. <a-tooltip
  302. :key="i"
  303. :id="id"
  304. placement="top"
  305. :title="(tooltips[id] || {}).title"
  306. :visible="(tooltips[id] || {}).visible || false"
  307. :autoAdjustOverflow="true"
  308. :getPopupContainer="getParentContainer"
  309. >
  310. <span
  311. @mouseover="
  312. () => {
  313. handleMouseoverCommono(row, col)
  314. }
  315. "
  316. @mouseout="
  317. () => {
  318. handleMouseoutCommono(row, col)
  319. }
  320. "
  321. >
  322. <j-input-pop
  323. :id="id"
  324. :key="i"
  325. :width="300"
  326. :height="210"
  327. :pop-container="`${caseId}tbody`"
  328. v-bind="buildProps(row, col)"
  329. style="width: 100%"
  330. :value="jInputPopValues[id]"
  331. :getCalendarContainer="getParentContainer"
  332. :placeholder="replaceProps(col, col.placeholder)"
  333. @change="(v) => handleChangeJInputPopCommon(v, id, row, col)"
  334. >
  335. </j-input-pop>
  336. </span>
  337. </a-tooltip>
  338. </template>
  339. <div v-else-if="col.type === formTypes.upload" :key="i + 1">
  340. <template v-if="uploadValues[id] != null">
  341. <a-input
  342. v-for="(file, fileKey) of [uploadValues[id] || {}]"
  343. :key="fileKey"
  344. :readOnly="true"
  345. :value="file.name"
  346. >
  347. <template slot="addonBefore">
  348. <div style="width: 30px">
  349. <a-tooltip
  350. v-if="file.status === 'uploading'"
  351. :title="`上传中(${Math.floor(file.percent)}%)`"
  352. >
  353. <a-icon type="loading" />
  354. </a-tooltip>
  355. <a-tooltip v-else-if="file.status === 'done'" title="上传完成">
  356. <a-icon type="check-circle" style="color: #00db00" />
  357. </a-tooltip>
  358. <a-tooltip v-else title="上传失败">
  359. <a-icon type="exclamation-circle" style="color: red" />
  360. </a-tooltip>
  361. </div>
  362. </template>
  363. <template v-if="col.allowDownload !== false || col.allowRemove !== false" slot="addonAfter">
  364. <div style="width: 30px">
  365. <a-dropdown
  366. :trigger="['click']"
  367. placement="bottomRight"
  368. :getPopupContainer="getParentContainer"
  369. >
  370. <a-tooltip title="操作" :getPopupContainer="getParentContainer">
  371. <a-icon v-if="file.status !== 'uploading'" type="setting" style="cursor: pointer" />
  372. </a-tooltip>
  373. <a-menu slot="overlay">
  374. <a-menu-item v-if="col.allowDownload !== false" @click="handleClickDownloadFile(id)">
  375. <span><a-icon type="download" />&nbsp;下载</span>
  376. </a-menu-item>
  377. <a-menu-item v-if="col.allowRemove !== false" @click="handleClickDelFile(id)">
  378. <span><a-icon type="delete" />&nbsp;删除</span>
  379. </a-menu-item>
  380. </a-menu>
  381. </a-dropdown>
  382. </div>
  383. </template>
  384. </a-input>
  385. </template>
  386. <div :hidden="uploadValues[id] != null">
  387. <a-tooltip
  388. :key="i"
  389. :id="id"
  390. placement="top"
  391. :title="(tooltips[id] || {}).title"
  392. :visible="(tooltips[id] || {}).visible || false"
  393. :autoAdjustOverflow="true"
  394. :getPopupContainer="getParentContainer"
  395. >
  396. <span
  397. @mouseover="
  398. () => {
  399. handleMouseoverCommono(row, col)
  400. }
  401. "
  402. @mouseout="
  403. () => {
  404. handleMouseoutCommono(row, col)
  405. }
  406. "
  407. >
  408. <a-upload
  409. name="file"
  410. :data="{ isup: 1 }"
  411. :multiple="false"
  412. :action="col.action"
  413. :headers="uploadGetHeaders(row, col)"
  414. :showUploadList="false"
  415. v-bind="buildProps(row, col)"
  416. @change="(v) => handleChangeUpload(v, id, row, col)"
  417. >
  418. <a-button icon="upload">{{ col.placeholder }}</a-button>
  419. </a-upload>
  420. </span>
  421. </a-tooltip>
  422. </div>
  423. </div>
  424. <!-- update-begin-author:taoyan date:0827 for:popup -->
  425. <template v-else-if="col.type === formTypes.popup">
  426. <a-tooltip
  427. :key="i"
  428. :id="id"
  429. placement="top"
  430. :title="(tooltips[id] || {}).title"
  431. :visible="(tooltips[id] || {}).visible || false"
  432. :autoAdjustOverflow="true"
  433. :getPopupContainer="getParentContainer"
  434. >
  435. <span
  436. @mouseover="
  437. () => {
  438. handleMouseoverCommono(row, col)
  439. }
  440. "
  441. @mouseout="
  442. () => {
  443. handleMouseoutCommono(row, col)
  444. }
  445. "
  446. >
  447. <j-popup
  448. :id="id"
  449. :key="i"
  450. v-bind="buildProps(row, col)"
  451. :placeholder="replaceProps(col, col.placeholder)"
  452. style="width: 100%"
  453. :value="getPopupValue(id)"
  454. :field="col.field || col.key"
  455. :org-fields="col.orgFields"
  456. :dest-fields="col.destFields"
  457. :code="col.popupCode"
  458. :groupId="caseId"
  459. @input="(value, others) => popupCallback(value, others, id, row, col, rowIndex)"
  460. />
  461. </span>
  462. </a-tooltip>
  463. </template>
  464. <!-- update-end-author:taoyan date:0827 for:popup -->
  465. <!-- update-begin-author:jsh date:20210308 for:popupJsh -->
  466. <template v-else-if="col.type === formTypes.popupJsh">
  467. <div style="width: 190px" :key="i">
  468. <a-tooltip
  469. :id="id"
  470. placement="top"
  471. :title="(tooltips[id] || {}).title"
  472. :visible="(tooltips[id] || {}).visible || false"
  473. :autoAdjustOverflow="true"
  474. :getPopupContainer="getParentContainer"
  475. >
  476. <span
  477. @mouseover="
  478. () => {
  479. handleMouseoverCommono(row, col)
  480. }
  481. "
  482. @mouseout="
  483. () => {
  484. handleMouseoutCommono(row, col)
  485. }
  486. "
  487. >
  488. <j-select-list
  489. :rows="getPopupJshRows(row)"
  490. :kind="col.kind"
  491. :multi="col.multi"
  492. :value="getPopupJshValue(id)"
  493. @change="(v) => handleChangePopupJshCommon(v, id, row, col, rowIndex)"
  494. />
  495. </span>
  496. </a-tooltip>
  497. </div>
  498. </template>
  499. <!-- update-end-author:jsh date:20210308 for:popupJsh -->
  500. <!-- update-beign-author:taoyan date:0827 for:文件/图片逻辑新增 -->
  501. <div v-else-if="col.type === formTypes.file" :key="i + 2">
  502. <template v-if="uploadValues[id] != null">
  503. <div
  504. v-for="(file, fileKey) of [uploadValues[id] || {}]"
  505. :key="fileKey"
  506. style="position: relative"
  507. >
  508. <a-tooltip v-if="file.status === 'uploading'" :title="`上传中(${Math.floor(file.percent)}%)`">
  509. <a-icon type="loading" style="color: red" />
  510. <span style="color: red; margin-left: 5px">{{ file.status }}</span>
  511. </a-tooltip>
  512. <a-tooltip v-else-if="file.status === 'done'" :title="file.name">
  513. <a-icon type="paper-clip" />
  514. <span style="margin-left: 5px">{{ getEllipsisWord(file.name, 5) }}</span>
  515. </a-tooltip>
  516. <a-tooltip v-else :title="file.name">
  517. <a-icon type="paper-clip" style="color: red" />
  518. <span style="color: red; margin-left: 5px">{{ getEllipsisWord(file.name, 5) }}</span>
  519. </a-tooltip>
  520. <template style="width: 30px">
  521. <a-dropdown
  522. :trigger="['click']"
  523. placement="bottomRight"
  524. :getPopupContainer="getParentContainer"
  525. style="margin-left: 10px"
  526. >
  527. <a-tooltip title="操作" :getPopupContainer="getParentContainer">
  528. <a-icon v-if="file.status !== 'uploading'" type="setting" style="cursor: pointer" />
  529. </a-tooltip>
  530. <a-menu slot="overlay">
  531. <a-menu-item v-if="col.allowDownload !== false" @click="handleClickDownFileByUrl(id)">
  532. <span><a-icon type="download" />&nbsp;下载</span>
  533. </a-menu-item>
  534. <a-menu-item @click="handleClickDelFile(id)">
  535. <span><a-icon type="delete" />&nbsp;删除</span>
  536. </a-menu-item>
  537. <a-menu-item @click="handleMoreOperation(id)">
  538. <span><a-icon type="bars" /> 更多</span>
  539. </a-menu-item>
  540. </a-menu>
  541. </a-dropdown>
  542. </template>
  543. </div>
  544. </template>
  545. <div :hidden="uploadValues[id] != null">
  546. <a-tooltip
  547. :key="i"
  548. :id="id"
  549. placement="top"
  550. :title="(tooltips[id] || {}).title"
  551. :visible="(tooltips[id] || {}).visible || false"
  552. :autoAdjustOverflow="true"
  553. :getPopupContainer="getParentContainer"
  554. >
  555. <span
  556. @mouseover="
  557. () => {
  558. handleMouseoverCommono(row, col)
  559. }
  560. "
  561. @mouseout="
  562. () => {
  563. handleMouseoutCommono(row, col)
  564. }
  565. "
  566. >
  567. <a-upload
  568. name="file"
  569. :data="{ isup: 1 }"
  570. :multiple="false"
  571. :action="getUploadAction(col.action)"
  572. :headers="uploadGetHeaders(row, col)"
  573. :showUploadList="false"
  574. v-bind="buildProps(row, col)"
  575. @change="(v) => handleChangeUpload(v, id, row, col)"
  576. >
  577. <a-button icon="upload">上传文件</a-button>
  578. </a-upload>
  579. </span>
  580. </a-tooltip>
  581. </div>
  582. </div>
  583. <div v-else-if="col.type === formTypes.image" :key="i + 3">
  584. <template v-if="uploadValues[id] != null">
  585. <div
  586. v-for="(file, fileKey) of [uploadValues[id] || {}]"
  587. :key="fileKey"
  588. style="position: relative"
  589. >
  590. <template
  591. v-if="
  592. !uploadValues[id] ||
  593. !(uploadValues[id]['url'] || uploadValues[id]['path'] || uploadValues[id]['message'])
  594. "
  595. >
  596. <a-icon type="loading" />
  597. </template>
  598. <template v-else-if="uploadValues[id]['path']">
  599. <img
  600. class="j-editable-image"
  601. :src="getCellImageView(id)"
  602. alt="无图片"
  603. @click="handleMoreOperation(id, 'img')"
  604. />
  605. </template>
  606. <template v-else>
  607. <a-icon
  608. type="exclamation-circle"
  609. style="color: red"
  610. @click="handleClickShowImageError(id)"
  611. />
  612. </template>
  613. <template slot="addonBefore">
  614. <div style="width: 30px">
  615. <a-tooltip
  616. v-if="file.status === 'uploading'"
  617. :title="`上传中(${Math.floor(file.percent)}%)`"
  618. >
  619. <a-icon type="loading" />
  620. </a-tooltip>
  621. <a-tooltip v-else-if="file.status === 'done'" title="上传完成">
  622. <a-icon type="check-circle" style="color: #00db00" />
  623. </a-tooltip>
  624. <a-tooltip v-else title="上传失败">
  625. <a-icon type="exclamation-circle" style="color: red" />
  626. </a-tooltip>
  627. </div>
  628. </template>
  629. <template style="width: 30px">
  630. <a-dropdown
  631. :trigger="['click']"
  632. placement="bottomRight"
  633. :getPopupContainer="getParentContainer"
  634. style="margin-left: 10px"
  635. >
  636. <a-tooltip title="操作" :getPopupContainer="getParentContainer">
  637. <a-icon v-if="file.status !== 'uploading'" type="setting" style="cursor: pointer" />
  638. </a-tooltip>
  639. <a-menu slot="overlay">
  640. <a-menu-item v-if="col.allowDownload !== false" @click="handleClickDownFileByUrl(id)">
  641. <span><a-icon type="download" />&nbsp;下载</span>
  642. </a-menu-item>
  643. <a-menu-item @click="handleClickDelFile(id)">
  644. <span><a-icon type="delete" />&nbsp;删除</span>
  645. </a-menu-item>
  646. <a-menu-item @click="handleMoreOperation(id, 'img')">
  647. <span><a-icon type="bars" /> 更多</span>
  648. </a-menu-item>
  649. </a-menu>
  650. </a-dropdown>
  651. </template>
  652. </div>
  653. </template>
  654. <div :hidden="uploadValues[id] != null">
  655. <a-tooltip
  656. :key="i"
  657. :id="id"
  658. placement="top"
  659. :title="(tooltips[id] || {}).title"
  660. :visible="(tooltips[id] || {}).visible || false"
  661. :autoAdjustOverflow="true"
  662. :getPopupContainer="getParentContainer"
  663. >
  664. <span
  665. @mouseover="
  666. () => {
  667. handleMouseoverCommono(row, col)
  668. }
  669. "
  670. @mouseout="
  671. () => {
  672. handleMouseoutCommono(row, col)
  673. }
  674. "
  675. >
  676. <a-upload
  677. name="file"
  678. :data="{ isup: 1 }"
  679. :multiple="false"
  680. :action="getUploadAction(col.action)"
  681. :headers="uploadGetHeaders(row, col)"
  682. :showUploadList="false"
  683. v-bind="buildProps(row, col)"
  684. @change="(v) => handleChangeUpload(v, id, row, col)"
  685. >
  686. <a-button icon="upload">上传图片</a-button>
  687. </a-upload>
  688. </span>
  689. </a-tooltip>
  690. </div>
  691. </div>
  692. <!-- update-end-author:taoyan date:0827 for:图片逻辑新增 -->
  693. <!-- radio-begin -->
  694. <template v-else-if="col.type === formTypes.radio">
  695. <a-tooltip
  696. :key="i"
  697. :id="id"
  698. placement="top"
  699. :title="(tooltips[id] || {}).title"
  700. :visible="(tooltips[id] || {}).visible || false"
  701. :autoAdjustOverflow="true"
  702. :getPopupContainer="getParentContainer"
  703. >
  704. <span
  705. @mouseover="
  706. () => {
  707. handleMouseoverCommono(row, col)
  708. }
  709. "
  710. @mouseout="
  711. () => {
  712. handleMouseoutCommono(row, col)
  713. }
  714. "
  715. >
  716. <a-radio-group
  717. :id="id"
  718. :key="i"
  719. v-bind="buildProps(row, col)"
  720. :value="radioValues[id]"
  721. @change="(e) => handleRadioChange(e.target.value, id, row, col)"
  722. >
  723. <a-radio v-for="(item, key) in col.options" :key="key" :value="item.value">{{
  724. item.text
  725. }}</a-radio>
  726. </a-radio-group>
  727. </span>
  728. </a-tooltip>
  729. </template>
  730. <!-- radio-end -->
  731. <!-- select多选 -begin -->
  732. <template v-else-if="col.type === formTypes.list_multi">
  733. <a-tooltip
  734. :key="i"
  735. :id="id"
  736. placement="top"
  737. :title="(tooltips[id] || {}).title"
  738. :visible="(tooltips[id] || {}).visible || false"
  739. :autoAdjustOverflow="true"
  740. :getPopupContainer="getParentContainer"
  741. >
  742. <span
  743. @mouseover="
  744. () => {
  745. handleMouseoverCommono(row, col)
  746. }
  747. "
  748. @mouseout="
  749. () => {
  750. handleMouseoutCommono(row, col)
  751. }
  752. "
  753. >
  754. <a-select
  755. :id="id"
  756. :key="i"
  757. mode="multiple"
  758. :maxTagCount="1"
  759. v-bind="buildProps(row, col)"
  760. style="width: 100%"
  761. :value="multiSelectValues[id]"
  762. :options="col.options"
  763. :getPopupContainer="getParentContainer"
  764. :placeholder="replaceProps(col, col.placeholder)"
  765. @change="(v) => handleMultiSelectChange(v, id, row, col)"
  766. allowClear
  767. >
  768. </a-select>
  769. </span>
  770. </a-tooltip>
  771. </template>
  772. <!-- select多选 -end -->
  773. <!-- select搜索 -begin -->
  774. <template v-else-if="col.type === formTypes.sel_search">
  775. <a-tooltip
  776. :key="i"
  777. :id="id"
  778. placement="top"
  779. :title="(tooltips[id] || {}).title"
  780. :visible="(tooltips[id] || {}).visible || false"
  781. :autoAdjustOverflow="true"
  782. :getPopupContainer="getParentContainer"
  783. >
  784. <span
  785. @mouseover="
  786. () => {
  787. handleMouseoverCommono(row, col)
  788. }
  789. "
  790. @mouseout="
  791. () => {
  792. handleMouseoutCommono(row, col)
  793. }
  794. "
  795. >
  796. <a-select
  797. :id="id"
  798. :key="i"
  799. showSearch
  800. optionFilterProp="children"
  801. :filterOption="filterOption"
  802. v-bind="buildProps(row, col)"
  803. style="width: 100%"
  804. :value="searchSelectValues[id]"
  805. :options="col.options"
  806. :getPopupContainer="getParentContainer"
  807. :placeholder="replaceProps(col, col.placeholder)"
  808. @change="(v) => handleSearchSelectChange(v, id, row, col)"
  809. allowClear
  810. >
  811. </a-select>
  812. </span>
  813. </a-tooltip>
  814. </template>
  815. <!-- select搜索 -end -->
  816. <div v-else-if="col.type === formTypes.slot" :key="i + 4">
  817. <a-tooltip
  818. :key="i"
  819. :id="id"
  820. placement="top"
  821. :title="(tooltips[id] || {}).title"
  822. :visible="(tooltips[id] || {}).visible || false"
  823. :autoAdjustOverflow="true"
  824. :getPopupContainer="getParentContainer"
  825. >
  826. <span
  827. @mouseover="
  828. () => {
  829. handleMouseoverCommono(row, col)
  830. }
  831. "
  832. @mouseout="
  833. () => {
  834. handleMouseoutCommono(row, col)
  835. }
  836. "
  837. >
  838. <slot
  839. :name="col.slot || col.slotName || col.key"
  840. :index="rowIndex"
  841. :text="slotValues[id]"
  842. :value="slotValues[id]"
  843. :column="col"
  844. :rowId="getCleanId(row.id)"
  845. :getValue="() => _getValueForSlot(row.id)"
  846. :caseId="caseId"
  847. :allValues="_getAllValuesForSlot()"
  848. :target="getVM()"
  849. :handleChange="(v) => handleChangeSlotCommon(v, id, row, col)"
  850. :handleFocus="(v) => handleFocusSlotCommon(v, id, row, col)"
  851. :isNotPass="notPassedIds.includes(col.key + row.id)"
  852. />
  853. </span>
  854. </a-tooltip>
  855. </div>
  856. <!-- else (normal) -->
  857. <span
  858. v-else
  859. :key="i + 5"
  860. v-bind="buildProps(row, col)"
  861. class="td-span"
  862. :title="inputValues[rowIndex][col.key]"
  863. >
  864. {{ inputValues[rowIndex][col.key] }}
  865. </span>
  866. </template>
  867. </div>
  868. </div>
  869. <!-- -- tr end -- -->
  870. </template>
  871. </draggable>
  872. <!-- 统计行 -->
  873. <div
  874. v-if="showStatisticsRow"
  875. class="tr"
  876. :style="{
  877. ...buildTrStyle(rows.length),
  878. height: '32px',
  879. }"
  880. >
  881. <div v-if="dragSort" class="td td-ds" :style="style.tdLeftDs"></div>
  882. <div v-if="dragSortAndNumber" class="td td-ds" :style="style.tdLeftDs"></div>
  883. <div v-if="rowNumber" class="td td-num" :style="style.tdLeft">
  884. <span v-if="!rowSelection">统计</span>
  885. </div>
  886. <div v-if="rowSelection" class="td td-cb" :style="style.tdLeft"></div>
  887. <!-- 右侧动态生成td -->
  888. <template v-for="col in columns">
  889. <div :key="col.key" class="td" v-show="col.type !== formTypes.hidden" :style="buildTdStyle(col)">
  890. <span v-show="col.type === formTypes.inputNumber" style="padding: 0 2px">{{
  891. statisticsColumns[col.key]
  892. }}</span>
  893. </div>
  894. </template>
  895. </div>
  896. </div>
  897. </div>
  898. <j-file-pop ref="filePop" @ok="handleFileSuccess"></j-file-pop>
  899. </div>
  900. </a-spin>
  901. </template>
  902. <script>
  903. import Vue from 'vue'
  904. import $ from 'jquery'
  905. import Draggable from 'vuedraggable'
  906. import { ACCESS_TOKEN } from '@/store/mutation-types'
  907. import { FormTypes, VALIDATE_NO_PASSED } from '@/utils/JEditableTableUtil'
  908. import { cloneObject, randomString, randomNumber } from '@/utils/util'
  909. import JDate from '@/components/jeecg/JDate'
  910. import { getFileAccessHttpUrl } from '@/api/manage'
  911. import JInputPop from '@/components/jeecg/minipop/JInputPop'
  912. import JFilePop from '@/components/jeecg/minipop/JFilePop'
  913. import JSelectList from '@/components/jeecgbiz/JSelectList'
  914. // import { BillModalMixin } from '../../../src/views/bill/mixins/BillModalMixin'
  915. // 行高,需要在实例加载完成前用到
  916. let rowHeight = 42
  917. export default {
  918. // mixins: [BillModalMixin],
  919. name: 'JEditableTable',
  920. components: {
  921. JDate,
  922. Draggable,
  923. JInputPop,
  924. JFilePop,
  925. JSelectList,
  926. VNodes: {
  927. functional: true,
  928. render: (h, ctx) => ctx.props.vnodes,
  929. },
  930. },
  931. provide() {
  932. return {
  933. parentIsJEditableTable: true,
  934. getDestroyCleanGroupRequest: () => this.destroyCleanGroupRequest,
  935. }
  936. },
  937. props: {
  938. // 列信息
  939. columns: {
  940. type: Array,
  941. required: true,
  942. },
  943. // 数据源
  944. dataSource: {
  945. type: Array,
  946. required: true,
  947. default: () => [],
  948. },
  949. // 是否显示操作按钮
  950. actionButton: {
  951. type: Boolean,
  952. default: false,
  953. },
  954. // 是否显示行号
  955. rowNumber: {
  956. type: Boolean,
  957. default: false,
  958. },
  959. // 是否可选择行
  960. rowSelection: {
  961. type: Boolean,
  962. default: false,
  963. },
  964. // 页面是否在加载中
  965. loading: {
  966. type: Boolean,
  967. default: false,
  968. },
  969. // 页面是否在加载中
  970. minWidth: {
  971. type: Number,
  972. default: 1500,
  973. },
  974. maxHeight: {
  975. type: Number,
  976. default: 400,
  977. },
  978. // 要禁用的行
  979. disabledRows: {
  980. type: Object,
  981. default() {
  982. return {}
  983. },
  984. },
  985. // 是否禁用全部组件
  986. disabled: {
  987. type: Boolean,
  988. default: false,
  989. },
  990. // 是否可拖拽排序
  991. dragSort: {
  992. type: Boolean,
  993. default: false,
  994. },
  995. // 是否可拖拽排序并显示行号
  996. dragSortAndNumber: {
  997. type: Boolean,
  998. default: false,
  999. },
  1000. dragSortKey: {
  1001. type: String,
  1002. default: 'orderNum',
  1003. },
  1004. },
  1005. data() {
  1006. return {
  1007. // 是否首次运行
  1008. isFirst: true,
  1009. // 当前实例是否是行编辑
  1010. isJEditableTable: true,
  1011. // caseId,用于防止有多个实例的时候会冲突
  1012. caseIdPrefix: '_jet-',
  1013. caseId: `_jet-${randomString(6)}-`,
  1014. // 临时ID标识,凡是以该标识结尾的ID都是临时ID,不添加到数据库中
  1015. tempId: `_tid-${randomString(6)}`,
  1016. // 存储document element 对象
  1017. el: {
  1018. inputTable: null,
  1019. tbody: null,
  1020. },
  1021. // 存储各个div的style
  1022. style: {
  1023. // 'max-height': '400px'
  1024. tbody: { left: '0px' },
  1025. // 左侧固定td的style
  1026. // 20200331 cfm modify
  1027. // tdLeft: { 'min-width': '4%', 'max-width': '45px' },
  1028. tdLeft: { 'min-width': '40px', 'max-width': '45px' },
  1029. tdLeftDs: { 'min-width': '30px', 'max-width': '35px' },
  1030. },
  1031. // 表单的类型
  1032. formTypes: FormTypes,
  1033. // 行数据
  1034. rows: [],
  1035. // 行高,height + padding + border
  1036. rowHeight,
  1037. // 滚动条顶部距离
  1038. scrollTop: 0,
  1039. // 绑定 select 的值
  1040. selectValues: {},
  1041. // 绑定 checkbox 的值
  1042. checkboxValues: {},
  1043. // 绑定 jdate 的值
  1044. jdateValues: {},
  1045. // 绑定jinputpop
  1046. jInputPopValues: {},
  1047. // 绑定插槽数据
  1048. slotValues: {},
  1049. // file 信息
  1050. uploadValues: {},
  1051. //popup信息
  1052. popupValues: {},
  1053. //popupJsh信息
  1054. popupJshValues: {},
  1055. radioValues: {},
  1056. metaCheckboxValues: {},
  1057. multiSelectValues: {},
  1058. searchSelectValues: {},
  1059. // 绑定左侧选择框已选择的id
  1060. selectedRowIds: [],
  1061. // 存储被删除行的id
  1062. deleteIds: [],
  1063. // 存储显示tooltip的信息
  1064. tooltips: {},
  1065. // 存储没有通过验证的inputId
  1066. notPassedIds: [],
  1067. // 当前是否正在拖拽排序
  1068. dragging: false,
  1069. // 是否有统计列
  1070. hasStatisticsColumn: false,
  1071. statisticsColumns: {},
  1072. // 只有在行编辑被销毁时才主动清空GroupRequest的内存
  1073. destroyCleanGroupRequest: false,
  1074. }
  1075. },
  1076. created() {
  1077. this.inputValues = []
  1078. // 当前显示的tr
  1079. this.visibleTrEls = []
  1080. this.disabledRowIds = this.disabledRowIds || []
  1081. },
  1082. // 计算属性
  1083. computed: {
  1084. // expandHeight = rows.length * rowHeight
  1085. getExpandHeight() {
  1086. let length = this.rows.length * this.rowHeight
  1087. if (this.showStatisticsRow) {
  1088. length += 34
  1089. }
  1090. return length
  1091. },
  1092. // 是否显示统计行
  1093. showStatisticsRow() {
  1094. return this.hasStatisticsColumn && this.rows.length > 0
  1095. },
  1096. // 获取是否选择了部分
  1097. getSelectIndeterminate() {
  1098. return this.selectedRowIds.length > 0 && this.selectedRowIds.length < this.rows.length
  1099. },
  1100. // 获取是否选择了全部
  1101. getSelectAll() {
  1102. return this.selectedRowIds.length === this.rows.length && this.rows.length > 0
  1103. },
  1104. tbodyStyle() {
  1105. let style = Object.assign({}, this.style.tbody)
  1106. // style['max-height'] = `${this.maxHeight}px`
  1107. style['width'] = this.realTrWidth
  1108. return style
  1109. },
  1110. showClearSelectButton() {
  1111. let count = 0
  1112. for (let key in this.disabledRows) {
  1113. if (this.disabledRows.hasOwnProperty(key)) count++
  1114. }
  1115. return count > 0
  1116. },
  1117. accessToken() {
  1118. return Vue.ls.get(ACCESS_TOKEN)
  1119. },
  1120. realTrWidth() {
  1121. let splice = ' + '
  1122. let calcWidth = 'calc('
  1123. this.columns.forEach((column, i) => {
  1124. let { type, width } = column
  1125. // 隐藏字段不参与计算
  1126. if (type !== FormTypes.hidden) {
  1127. if (typeof width === 'number') {
  1128. calcWidth += width + 'px'
  1129. } else if (typeof width === 'string') {
  1130. calcWidth += width
  1131. } else {
  1132. calcWidth += '120px'
  1133. }
  1134. calcWidth += splice
  1135. }
  1136. })
  1137. if (calcWidth.endsWith(splice)) {
  1138. calcWidth = calcWidth.substring(0, calcWidth.length - splice.length)
  1139. }
  1140. calcWidth += ')'
  1141. // console.log('calcWidth: ', calcWidth)
  1142. return calcWidth
  1143. },
  1144. },
  1145. // 侦听器
  1146. watch: {
  1147. rows: {
  1148. immediate: true,
  1149. handler(val, old) {
  1150. // val.forEach(item => {
  1151. // for (let inputValue of this.inputValues) {
  1152. // if (inputValue.id === item.id) {
  1153. // item['dbFieldName'] = inputValue['dbFieldName']
  1154. // break
  1155. // }
  1156. // }
  1157. // })
  1158. // console.log('watch.rows:', cloneObject({ val, old }))
  1159. },
  1160. },
  1161. dataSource: {
  1162. immediate: true,
  1163. handler: function (newValue) {
  1164. // 兼容IE
  1165. this.getElementPromise('tbody').then(() => {
  1166. this.initialize()
  1167. this._pushByDataSource(newValue)
  1168. })
  1169. },
  1170. },
  1171. columns: {
  1172. immediate: true,
  1173. handler(columns) {
  1174. // 兼容IE
  1175. this.getElementPromise('tbody').then(() => {
  1176. columns.forEach((column) => {
  1177. if (
  1178. column.type === FormTypes.select ||
  1179. column.type === FormTypes.list_multi ||
  1180. column.type === FormTypes.sel_search
  1181. ) {
  1182. // 兼容 旧版本 options
  1183. if (column.options instanceof Array) {
  1184. column.options = column.options.map((item) => {
  1185. if (item) {
  1186. return {
  1187. ...item,
  1188. text: item.text || item.title,
  1189. title: item.text || item.title,
  1190. }
  1191. }
  1192. return {}
  1193. })
  1194. }
  1195. }
  1196. })
  1197. })
  1198. },
  1199. },
  1200. // 当selectRowIds改变时触发事件
  1201. selectedRowIds(newValue) {
  1202. this.$emit(
  1203. 'selectRowChange',
  1204. cloneObject(newValue).map((i) => this.getCleanId(i))
  1205. )
  1206. },
  1207. },
  1208. mounted() {
  1209. let vm = this
  1210. /** 监听滚动条事件 */
  1211. this.getElement('inputTable').onscroll = function (event) {
  1212. vm.syncScrollBar(event.target.scrollLeft)
  1213. }
  1214. this.getElement('tbody').onscroll = function (event) {
  1215. // vm.recalcTrHiddenItem(event.target.scrollTop)
  1216. }
  1217. let { thead, scrollView } = this.$refs
  1218. scrollView.onscroll = function (event) {
  1219. // console.log(event.target.scrollTop, ' - ', event.target.scrollLeft)
  1220. thead.scrollLeft = event.target.scrollLeft
  1221. vm.recalcTrHiddenItem(event.target.scrollTop)
  1222. }
  1223. },
  1224. methods: {
  1225. getElement(id, noCaseId = false) {
  1226. if (!this.el[id]) {
  1227. this.el[id] = document.getElementById((noCaseId ? '' : this.caseId) + id)
  1228. }
  1229. return this.el[id]
  1230. },
  1231. getElementPromise(id, noCaseId = false) {
  1232. return new Promise((resolve) => {
  1233. let timer = setInterval(() => {
  1234. let element = this.getElement(id, noCaseId)
  1235. if (element) {
  1236. clearInterval(timer)
  1237. resolve(element)
  1238. }
  1239. }, 10)
  1240. })
  1241. },
  1242. /** 初始化列表 */
  1243. initialize() {
  1244. this.visibleTrEls = []
  1245. // 判断是否是首次进入该方法,如果是就不清空行,防止删除了预添加的数据
  1246. if (!this.isFirst) {
  1247. // inputValues:用来存储input表单的值
  1248. // 数组里的每项都是一个对象,对象里每个key都是input的rowKey,值就是input的值,其中有个id的字段来区分
  1249. // 示例:
  1250. // [{
  1251. // id: "_jet-4sp0iu-15541771111770"
  1252. // dbDefaultVal: "aaa",
  1253. // dbFieldName: "bbb",
  1254. // dbFieldTxt: "ccc",
  1255. // dbLength: 32
  1256. // }]
  1257. this.inputValues = []
  1258. this.rows = []
  1259. this.deleteIds = []
  1260. this.selectValues = {}
  1261. this.checkboxValues = {}
  1262. this.jdateValues = {}
  1263. this.jInputPopValues = {}
  1264. this.slotValues = {}
  1265. this.selectedRowIds = []
  1266. this.tooltips = {}
  1267. this.notPassedIds = []
  1268. this.uploadValues = []
  1269. this.popupValues = []
  1270. this.popupJshValues = []
  1271. this.radioValues = []
  1272. this.multiSelectValues = []
  1273. this.searchSelectValues = []
  1274. this.scrollTop = 0
  1275. this.$nextTick(() => {
  1276. this.getElement('tbody').scrollTop = 0
  1277. })
  1278. } else {
  1279. this.isFirst = false
  1280. }
  1281. },
  1282. /** 同步滚动条状态 */
  1283. syncScrollBar(scrollLeft) {
  1284. // this.style.tbody.left = `${scrollLeft}px`
  1285. // this.getElement('tbody').scrollLeft = scrollLeft
  1286. },
  1287. /** 重置滚动条位置,参数留空则滚动到上次记录的位置 */
  1288. resetScrollTop(top) {
  1289. let { scrollView } = this.$refs
  1290. if (top != null && typeof top === 'number') {
  1291. scrollView.scrollTop = top
  1292. } else {
  1293. scrollView.scrollTop = this.scrollTop
  1294. }
  1295. },
  1296. /** 重新计算需要隐藏或显示的tr */
  1297. recalcTrHiddenItem(top) {
  1298. let diff = top - this.scrollTop
  1299. if (diff < 0) {
  1300. diff = this.scrollTop - top
  1301. }
  1302. // 只有在滚动了百分之三十的行高的距离时才进行更新
  1303. if (diff >= this.rowHeight * 0.3) {
  1304. this.scrollTop = top
  1305. // 更新form表单的值
  1306. this.$nextTick(() => {
  1307. this.updateFormValues()
  1308. })
  1309. }
  1310. },
  1311. /** 生成id */
  1312. generateId(rows) {
  1313. if (!(rows instanceof Array)) {
  1314. rows = this.rows || []
  1315. }
  1316. let timestamp = new Date().getTime()
  1317. return `${this.caseId}${timestamp}${rows.length}${randomNumber(6)}${this.tempId}`
  1318. },
  1319. /** push 一条数据 */
  1320. push(record, update = true, rows, insertIndex = null, setDefaultValue = true) {
  1321. return this._pushByDataSource([record], [insertIndex], update, rows, setDefaultValue)
  1322. },
  1323. /**
  1324. * push 数据
  1325. *
  1326. * @param dataSource 数据源
  1327. * @param insertIndexes 行插入位置,和dataSource的下标一一对应
  1328. * @param update 是否更新
  1329. * @param rows 若不传就使用 this.rows
  1330. * @param setDefaultValue 是否填充默认值
  1331. *
  1332. */
  1333. _pushByDataSource(dataSource, insertIndexes = null, update = true, rows = null, setDefaultValue = false) {
  1334. if (!(rows instanceof Array)) {
  1335. rows = [...this.rows] || []
  1336. }
  1337. let checkboxValues = { ...this.checkboxValues }
  1338. let selectValues = { ...this.selectValues }
  1339. let jdateValues = { ...this.jdateValues }
  1340. let jInputPopValues = { ...this.jInputPopValues }
  1341. let slotValues = { ...this.slotValues }
  1342. let uploadValues = { ...this.uploadValues }
  1343. let popupValues = { ...this.popupValues }
  1344. let popupJshValues = { ...this.popupJshValues }
  1345. let radioValues = { ...this.radioValues }
  1346. let multiSelectValues = { ...this.multiSelectValues }
  1347. let searchSelectValues = { ...this.searchSelectValues }
  1348. // 禁用行的id
  1349. let disabledRowIds = this.disabledRowIds || []
  1350. dataSource.forEach((data, newValueIndex) => {
  1351. // 不能直接更改数据源的id
  1352. let dataId = data.id
  1353. // 判断源数据是否带有id
  1354. if (dataId == null || dataId === '') {
  1355. dataId = this.generateId(rows)
  1356. } else if (!this.hasCaseId(dataId)) {
  1357. dataId = this.caseId + dataId
  1358. }
  1359. let row = { id: dataId }
  1360. let value = { id: dataId }
  1361. let disabled = false
  1362. this.columns.forEach((column) => {
  1363. let inputId = column.key + value.id
  1364. let sourceValue = data[column.key] == null ? '' : data[column.key]
  1365. let defaultValue = null
  1366. if (setDefaultValue) {
  1367. defaultValue = column.defaultValue || (column.defaultValue === 0 ? 0 : '')
  1368. if (defaultValue instanceof Array) {
  1369. defaultValue = defaultValue.join(',')
  1370. }
  1371. sourceValue = typeof sourceValue === 'number' || sourceValue ? sourceValue : defaultValue
  1372. }
  1373. let sourceValueIsEmpty = sourceValue == null || sourceValue === ''
  1374. if (column.type === FormTypes.inputNumber) {
  1375. // 判断是否是排序字段,如果是就赋最大值
  1376. if (column.isOrder === true) {
  1377. value[column.key] = this.getInputNumberMaxValue(column) + 1
  1378. } else {
  1379. value[column.key] = sourceValue
  1380. }
  1381. // 判断是否是统计列
  1382. if (column.statistics) {
  1383. this.hasStatisticsColumn = true
  1384. if (!this.statisticsColumns[column.key]) {
  1385. this.$set(this.statisticsColumns, column.key, 0)
  1386. }
  1387. }
  1388. } else if (column.type === FormTypes.checkbox) {
  1389. // 判断是否设定了customValue(自定义值)
  1390. if (column.customValue instanceof Array) {
  1391. let customValue = (column.customValue[0] || '').toString()
  1392. if (sourceValueIsEmpty && setDefaultValue) {
  1393. sourceValue = column.defaultChecked ? customValue : sourceValue
  1394. }
  1395. checkboxValues[inputId] = sourceValue === customValue
  1396. } else {
  1397. if (sourceValueIsEmpty && setDefaultValue) {
  1398. checkboxValues[inputId] = !!column.defaultChecked
  1399. } else {
  1400. checkboxValues[inputId] = sourceValue
  1401. }
  1402. }
  1403. } else if (column.type === FormTypes.select) {
  1404. if (!sourceValueIsEmpty) {
  1405. // 判断是否是多选
  1406. if (typeof sourceValue === 'string' && (column.props || {})['mode'] === 'multiple') {
  1407. sourceValue = sourceValue.split(',')
  1408. }
  1409. selectValues[inputId] = sourceValue
  1410. } else {
  1411. selectValues[inputId] = undefined
  1412. }
  1413. } else if (column.type === FormTypes.date || column.type === FormTypes.datetime) {
  1414. jdateValues[inputId] = sourceValue
  1415. } else if (column.type === FormTypes.slot) {
  1416. slotValues[inputId] = sourceValue
  1417. } else if (column.type === FormTypes.popup) {
  1418. popupValues[inputId] = sourceValue
  1419. } else if (column.type === FormTypes.popupJsh) {
  1420. popupJshValues[inputId] = sourceValue
  1421. } else if (column.type === FormTypes.input_pop) {
  1422. jInputPopValues[inputId] = sourceValue
  1423. } else if (column.type === FormTypes.radio) {
  1424. radioValues[inputId] = sourceValue
  1425. } else if (column.type === FormTypes.sel_search) {
  1426. searchSelectValues[inputId] = sourceValue
  1427. } else if (column.type === FormTypes.list_multi) {
  1428. if (typeof sourceValue === 'string' && sourceValue.length > 0) {
  1429. multiSelectValues[inputId] = sourceValue.split(',')
  1430. } else {
  1431. multiSelectValues[inputId] = []
  1432. }
  1433. } else if (
  1434. column.type === FormTypes.upload ||
  1435. column.type === FormTypes.file ||
  1436. column.type === FormTypes.image
  1437. ) {
  1438. if (sourceValue) {
  1439. let fileName = ''
  1440. if (sourceValue.indexOf(',') > 0) {
  1441. let sourceValue2 = sourceValue.split(',')[0]
  1442. fileName = sourceValue2.substring(sourceValue2.lastIndexOf('/') + 1)
  1443. } else {
  1444. fileName = sourceValue.substring(sourceValue.lastIndexOf('/') + 1)
  1445. }
  1446. uploadValues[inputId] = {
  1447. name: fileName,
  1448. status: 'done',
  1449. path: sourceValue,
  1450. }
  1451. }
  1452. } else {
  1453. value[column.key] = sourceValue
  1454. }
  1455. // 解析disabledRows
  1456. for (let columnKey in this.disabledRows) {
  1457. // 判断是否有该属性
  1458. if (this.disabledRows.hasOwnProperty(columnKey) && data.hasOwnProperty(columnKey)) {
  1459. if (disabled !== true) {
  1460. let temp = this.disabledRows[columnKey]
  1461. // 禁用规则可以是一个数组
  1462. if (temp instanceof Array) {
  1463. disabled = temp.includes(data[columnKey])
  1464. } else {
  1465. disabled = temp === data[columnKey]
  1466. }
  1467. if (disabled) {
  1468. disabledRowIds.push(row.id)
  1469. }
  1470. }
  1471. }
  1472. }
  1473. })
  1474. // 插入行而不是添加到最后
  1475. let added = false
  1476. if (insertIndexes instanceof Array) {
  1477. let insertIndex = insertIndexes[newValueIndex]
  1478. if (typeof insertIndex === 'number') {
  1479. added = true
  1480. rows.splice(insertIndex, 0, row)
  1481. this.inputValues.splice(insertIndex, 0, value)
  1482. }
  1483. }
  1484. if (!added) {
  1485. rows.push(row)
  1486. this.inputValues.push(value)
  1487. }
  1488. })
  1489. // 启用了拖动排序,就重新计算排序编号
  1490. if (this.dragSort) {
  1491. this.inputValues.forEach((item, index) => {
  1492. item[this.dragSortKey] = index + 1
  1493. })
  1494. }
  1495. this.disabledRowIds = disabledRowIds
  1496. this.checkboxValues = checkboxValues
  1497. this.selectValues = selectValues
  1498. this.jdateValues = jdateValues
  1499. this.jInputPopValues = jInputPopValues
  1500. this.slotValues = slotValues
  1501. this.uploadValues = uploadValues
  1502. this.popupValues = popupValues
  1503. this.popupJshValues = popupJshValues
  1504. this.radioValues = radioValues
  1505. this.multiSelectValues = multiSelectValues
  1506. this.searchSelectValues = searchSelectValues
  1507. // 重新计算所有统计列
  1508. this.recalcAllStatisticsColumns()
  1509. // 更新到 dom
  1510. if (update) {
  1511. this.rows = rows
  1512. // 更新form表单的值
  1513. this.$nextTick(() => {
  1514. this.updateFormValues()
  1515. })
  1516. }
  1517. return rows
  1518. },
  1519. /** 获取某一数字输入框列中的最大的值 */
  1520. getInputNumberMaxValue(column) {
  1521. let maxNum = 0
  1522. this.inputValues.forEach((item, index) => {
  1523. let val = item[column.key],
  1524. num
  1525. try {
  1526. num = parseInt(val)
  1527. } catch {
  1528. num = 0
  1529. }
  1530. // 把首次循环的结果当成最大值
  1531. if (index === 0) {
  1532. maxNum = num
  1533. } else {
  1534. maxNum = num > maxNum ? num : maxNum
  1535. }
  1536. })
  1537. return maxNum
  1538. },
  1539. /** 添加一行 */
  1540. add(num = 1, forceScrollToBottom = false) {
  1541. if (num < 1) return
  1542. // let timestamp = new Date().getTime()
  1543. let rows = this.rows
  1544. let row
  1545. for (let i = 0; i < num; i++) {
  1546. rows = this.push({}, false, rows)
  1547. row = rows[rows.length - 1]
  1548. }
  1549. this.rows = rows
  1550. this.$nextTick(() => {
  1551. this.updateFormValues()
  1552. })
  1553. // 触发add事件
  1554. this.$emit('added', {
  1555. row: (() => {
  1556. let r = Object.assign({}, row)
  1557. r.id = this.getCleanId(r.id)
  1558. return r
  1559. })(),
  1560. target: this,
  1561. })
  1562. // 设置滚动条位置
  1563. let tbody = this.getElement('tbody')
  1564. let offsetHeight = tbody.offsetHeight
  1565. let realScrollTop = tbody.scrollTop + offsetHeight
  1566. if (forceScrollToBottom === false) {
  1567. // 只有滚动条在底部的时候才自动滚动
  1568. if (!(tbody.scrollHeight - realScrollTop <= 10)) {
  1569. return
  1570. }
  1571. }
  1572. this.$nextTick(() => {
  1573. tbody.scrollTop = tbody.scrollHeight
  1574. })
  1575. this.$nextTick(() => {
  1576. this.autoJumpNextInputBill()
  1577. })
  1578. },
  1579. /**
  1580. * 在指定位置添加一行
  1581. * @param insertIndex 添加位置下标
  1582. * @param num 添加的行数,默认1
  1583. */
  1584. insert(insertIndex, num = 1) {
  1585. if (!insertIndex && num < 1) return
  1586. let rows = this.rows
  1587. let newRows = []
  1588. for (let i = 0; i < num; i++) {
  1589. let row = { id: this.generateId(rows) }
  1590. rows = this.push(row, false, rows, insertIndex)
  1591. newRows.push(row)
  1592. }
  1593. // 同步更改
  1594. this.rows = rows
  1595. this.$nextTick(() => {
  1596. this.recalcSortNumber()
  1597. this.forceUpdateFormValues()
  1598. })
  1599. // 触发 insert 事件
  1600. this.$emit('inserted', {
  1601. rows: newRows.map((row) => {
  1602. let r = cloneObject(row)
  1603. r.id = this.getCleanId(r.id)
  1604. return r
  1605. }),
  1606. num,
  1607. insertIndex,
  1608. target: this,
  1609. })
  1610. this.$nextTick(() => {
  1611. this.autoJumpNextInputBill()
  1612. })
  1613. },
  1614. /** 删除被选中的行 */
  1615. removeSelectedRows() {
  1616. this.removeRows(this.selectedRowIds)
  1617. this.selectedRowIds = []
  1618. },
  1619. /** 删除一行或多行 */
  1620. removeRows(id) {
  1621. let ids = id
  1622. if (!(id instanceof Array)) {
  1623. if (typeof id === 'string') {
  1624. ids = [id]
  1625. } else {
  1626. throw `JEditableTable.removeRows() 函数需要的参数可以是string或Array类型,但提供的却是${typeof id}`
  1627. }
  1628. }
  1629. let rows = cloneObject(this.rows)
  1630. ids.forEach((removeId) => {
  1631. removeId = this.getCleanId(removeId)
  1632. // 找到每个id对应的真实index并删除
  1633. const findAndDelete = (arr) => {
  1634. for (let i = 0; i < arr.length; i++) {
  1635. let currentId = this.getCleanId(arr[i].id)
  1636. if (currentId === removeId) {
  1637. arr.splice(i, 1)
  1638. return true
  1639. }
  1640. }
  1641. }
  1642. // 找到rows对应的index,并删除
  1643. if (findAndDelete(rows)) {
  1644. // 找到values对应的index,并删除
  1645. findAndDelete(this.inputValues)
  1646. // 将caseId去除
  1647. let id = this.getCleanId(removeId)
  1648. this.deleteIds.push(id)
  1649. }
  1650. })
  1651. this.rows = rows
  1652. this.$emit('deleted', this.getDeleteIds(), this)
  1653. this.$nextTick(() => {
  1654. // 更新formValues
  1655. this.updateFormValues()
  1656. // 重新计算统计
  1657. this.recalcAllStatisticsColumns()
  1658. })
  1659. return true
  1660. },
  1661. /** 获取表格表单里的值(异步版) */
  1662. getValuesAsync(options = {}, callback) {
  1663. let { validate, rowIds, deleteTempId } = options
  1664. if (typeof validate !== 'boolean') validate = true
  1665. if (!(rowIds instanceof Array)) rowIds = null
  1666. // 是否删除临时ID,默认为 false
  1667. if (typeof deleteTempId !== 'boolean') deleteTempId = false
  1668. // console.log('options:', { validate, rowIds })
  1669. let asyncCount = 0
  1670. let error = 0
  1671. let inputValues = cloneObject(this.inputValues)
  1672. let tooltips = Object.assign({}, this.tooltips)
  1673. let notPassedIds = cloneObject(this.notPassedIds)
  1674. // 用于存储合并后的值
  1675. let values = []
  1676. // 遍历inputValues来获取每行的值
  1677. for (let value of inputValues) {
  1678. let rowIdsFlag = false
  1679. // 如果带有rowIds,那么就只存这几行的数据
  1680. if (rowIds == null) {
  1681. rowIdsFlag = true
  1682. } else {
  1683. for (let rowId of rowIds) {
  1684. if (this.getCleanId(rowId) === this.getCleanId(value.id)) {
  1685. rowIdsFlag = true
  1686. break
  1687. }
  1688. }
  1689. }
  1690. if (!rowIdsFlag) continue
  1691. this.columns.forEach((column) => {
  1692. let inputId = column.key + value.id
  1693. if (column.type === FormTypes.checkbox) {
  1694. let checked = this.checkboxValues[inputId]
  1695. if (column.customValue instanceof Array) {
  1696. value[column.key] = checked ? column.customValue[0] : column.customValue[1]
  1697. } else {
  1698. value[column.key] = checked
  1699. }
  1700. } else if (column.type === FormTypes.select) {
  1701. let selected = this.selectValues[inputId]
  1702. if (selected instanceof Array) {
  1703. value[column.key] = cloneObject(selected)
  1704. } else {
  1705. value[column.key] = selected
  1706. }
  1707. } else if (column.type === FormTypes.date || column.type === FormTypes.datetime) {
  1708. value[column.key] = this.jdateValues[inputId]
  1709. } else if (column.type === FormTypes.input_pop) {
  1710. value[column.key] = this.jInputPopValues[inputId]
  1711. } else if (column.type === FormTypes.upload) {
  1712. value[column.key] = cloneObject(this.uploadValues[inputId] || null)
  1713. } else if (column.type === FormTypes.image || column.type === FormTypes.file) {
  1714. let currUploadObj = cloneObject(this.uploadValues[inputId] || null)
  1715. if (currUploadObj) {
  1716. value[column.key] = currUploadObj['path'] || null
  1717. }
  1718. } else if (column.type === FormTypes.popup) {
  1719. if (!value[column.key]) {
  1720. value[column.key] = this.popupValues[inputId] || null
  1721. }
  1722. } else if (column.type === FormTypes.popupJsh) {
  1723. if (!value[column.key]) {
  1724. value[column.key] = this.popupJshValues[inputId] || null
  1725. }
  1726. } else if (column.type === FormTypes.radio) {
  1727. value[column.key] = this.radioValues[inputId]
  1728. } else if (column.type === FormTypes.sel_search) {
  1729. value[column.key] = this.searchSelectValues[inputId]
  1730. } else if (column.type === FormTypes.list_multi) {
  1731. if (!this.multiSelectValues[inputId] || this.multiSelectValues[inputId].length === 0) {
  1732. value[column.key] = ''
  1733. } else {
  1734. value[column.key] = this.multiSelectValues[inputId].join(',')
  1735. }
  1736. } else if (column.type === FormTypes.slot) {
  1737. value[column.key] = this.slotValues[inputId]
  1738. }
  1739. // 检查表单验证
  1740. if (validate === true) {
  1741. const handleValidateOneInput = (results) => {
  1742. tooltips[inputId] = results[0]
  1743. if (tooltips[inputId].passed === false) {
  1744. error++
  1745. // if (error++ === 0) {
  1746. // let element = document.getElementById(inputId)
  1747. // while (element.className !== 'tr') {
  1748. // element = element.parentElement
  1749. // }
  1750. // this.jumpToId(inputId, element)
  1751. // }
  1752. }
  1753. tooltips[inputId].visible = false
  1754. notPassedIds = results[1]
  1755. }
  1756. asyncCount++
  1757. let results = this.validateOneInputAsync(
  1758. value[column.key],
  1759. value,
  1760. column,
  1761. notPassedIds,
  1762. false,
  1763. 'getValues',
  1764. (results) => {
  1765. handleValidateOneInput(results)
  1766. asyncCount--
  1767. }
  1768. )
  1769. handleValidateOneInput(results)
  1770. }
  1771. })
  1772. // 删除 tempId
  1773. if (deleteTempId && this.isTempId(value.id)) {
  1774. delete value.id
  1775. } else {
  1776. value.id = this.getCleanId(value.id)
  1777. }
  1778. values.push(value)
  1779. }
  1780. if (validate === true) {
  1781. this.tooltips = tooltips
  1782. this.notPassedIds = notPassedIds
  1783. }
  1784. const timer = setInterval(() => {
  1785. if (asyncCount === 0) {
  1786. clearInterval(timer)
  1787. if (typeof callback === 'function') {
  1788. callback({ error, values })
  1789. }
  1790. }
  1791. }, 10)
  1792. return { error, values }
  1793. },
  1794. /** 获取表格表单里的值(同步版) */
  1795. getValuesSync(options = {}) {
  1796. return this.getValuesAsync(options)
  1797. },
  1798. /** 获取表格表单里的值 */
  1799. getValues(callback, validate = true, rowIds) {
  1800. this.getValuesAsync({ validate, rowIds }, ({ error, values }) => {
  1801. if (typeof callback === 'function') {
  1802. callback(error, values)
  1803. }
  1804. })
  1805. },
  1806. /** getValues的Promise版 */
  1807. getValuesPromise(validate = true, rowIds, deleteTempId) {
  1808. return new Promise((resolve, reject) => {
  1809. this.getValuesAsync({ validate, rowIds, deleteTempId }, ({ error, values }) => {
  1810. if (error === 0) {
  1811. resolve(values)
  1812. } else {
  1813. reject(VALIDATE_NO_PASSED)
  1814. }
  1815. })
  1816. })
  1817. },
  1818. /** 获取被删除项的id */
  1819. getDeleteIds() {
  1820. return cloneObject(this.deleteIds)
  1821. },
  1822. /** 获取所有的数据,包括values、deleteIds */
  1823. getAll(validate, deleteTempId) {
  1824. return new Promise((resolve, reject) => {
  1825. let deleteIds = this.getDeleteIds()
  1826. this.getValuesPromise(validate, null, deleteTempId)
  1827. .then((values) => {
  1828. resolve({ values, deleteIds })
  1829. })
  1830. .catch((error) => {
  1831. reject(error)
  1832. })
  1833. })
  1834. },
  1835. /** Sync 获取所有的数据,包括values、deleteIds */
  1836. getAllSync(validate, rowIds, deleteTempId) {
  1837. let result = this.getValuesSync({ validate, rowIds, deleteTempId })
  1838. result.deleteIds = this.getDeleteIds()
  1839. return result
  1840. },
  1841. // slot 获取值
  1842. _getValueForSlot(rowId) {
  1843. return this.getValuesSync({ rowIds: [rowId] }).values[0]
  1844. },
  1845. _getAllValuesForSlot() {
  1846. return cloneObject({
  1847. inputValues: this.inputValues,
  1848. selectValues: this.selectValues,
  1849. checkboxValues: this.checkboxValues,
  1850. jdateValues: this.jdateValues,
  1851. jInputPopValues: this.jInputPopValues,
  1852. slotValues: this.slotValues,
  1853. uploadValues: this.uploadValues,
  1854. popupValues: this.popupValues,
  1855. popupJshValues: this.popupJshValues,
  1856. radioValues: this.radioValues,
  1857. multiSelectValues: this.multiSelectValues,
  1858. searchSelectValues: this.searchSelectValues,
  1859. })
  1860. },
  1861. /** 设置某行某列的值 */
  1862. setValues(values) {
  1863. values.forEach((item) => {
  1864. let { rowKey, values: newValues } = item
  1865. rowKey = this.getCleanId(rowKey)
  1866. for (let newValueKey in newValues) {
  1867. if (newValues.hasOwnProperty(newValueKey)) {
  1868. let newValue = newValues[newValueKey]
  1869. let edited = false // 已被修改
  1870. this.inputValues.forEach((value) => {
  1871. // 在inputValues中找到了该字段
  1872. if (rowKey === this.getCleanId(value.id)) {
  1873. if (value.hasOwnProperty(newValueKey)) {
  1874. edited = true
  1875. value[newValueKey] = newValue
  1876. }
  1877. }
  1878. })
  1879. let modelKey = `${newValueKey}${this.caseId}${rowKey}`
  1880. // 在 selectValues 中寻找值
  1881. if (!edited) {
  1882. if (newValue !== 0 && !newValue) {
  1883. edited = this.setOneValue(this.selectValues, modelKey, undefined)
  1884. } else {
  1885. edited = this.setOneValue(this.selectValues, modelKey, newValue)
  1886. }
  1887. }
  1888. // 在 checkboxValues 中寻找值
  1889. if (!edited) {
  1890. edited = this.setOneValue(this.checkboxValues, modelKey, newValue)
  1891. }
  1892. // 在 jdateValues 中寻找值
  1893. if (!edited) {
  1894. edited = this.setOneValue(this.jdateValues, modelKey, newValue)
  1895. }
  1896. // 在 jInputPopValues 中寻找值
  1897. if (!edited) {
  1898. edited = this.setOneValue(this.jInputPopValues, modelKey, newValue)
  1899. }
  1900. // 在 slotValues 中寻找值
  1901. if (!edited) {
  1902. edited = this.setOneValue(this.slotValues, modelKey, newValue)
  1903. }
  1904. // 在 uploadValues 中寻找值
  1905. if (!edited) {
  1906. edited = this.setOneValue(this.uploadValues, modelKey, newValue)
  1907. }
  1908. // 在 popupValues 中寻找值
  1909. if (!edited) {
  1910. edited = this.setOneValue(this.popupValues, modelKey, newValue)
  1911. }
  1912. // 在 popupJshValues 中寻找值
  1913. if (!edited) {
  1914. edited = this.setOneValue(this.popupJshValues, modelKey, newValue)
  1915. }
  1916. // 在 radioValues 中寻找值
  1917. if (!edited) {
  1918. edited = this.setOneValue(this.radioValues, modelKey, newValue)
  1919. }
  1920. // 在 multiSelectValues 中寻找值
  1921. if (!edited) {
  1922. edited = this.setOneValue(this.multiSelectValues, modelKey, newValue)
  1923. }
  1924. // 在 searchSelectValues 中寻找值
  1925. if (!edited) {
  1926. edited = this.setOneValue(this.searchSelectValues, modelKey, newValue)
  1927. }
  1928. }
  1929. }
  1930. })
  1931. // 强制更新formValues
  1932. this.forceUpdateFormValues()
  1933. },
  1934. setOneValue(valuesObject, modelKey, value) {
  1935. let key = this.valuesHasOwnProperty(valuesObject, modelKey)
  1936. if (key) {
  1937. this.$set(valuesObject, key, value)
  1938. return true
  1939. }
  1940. return false
  1941. },
  1942. valuesHasOwnProperty(values, ownProperty) {
  1943. let key = ownProperty
  1944. if (values.hasOwnProperty(key)) {
  1945. return key
  1946. }
  1947. if (values.hasOwnProperty(key + this.tempId)) {
  1948. return key + this.tempId
  1949. }
  1950. return null
  1951. },
  1952. /** 跳转到指定位置 */
  1953. // jumpToId(id, element) {
  1954. // if (element == null) {
  1955. // element = document.getElementById(id)
  1956. // }
  1957. // if (element != null) {
  1958. // console.log(this.getElement('tbody').scrollTop, element.offsetTop)
  1959. // this.getElement('tbody').scrollTop = element.offsetTop
  1960. // console.log(this.getElement('tbody').scrollTop, element.offsetTop)
  1961. // }
  1962. // },
  1963. /**
  1964. * 验证单个表单,异步版
  1965. *
  1966. * @param value 校验的值
  1967. * @param row 校验的行
  1968. * @param column 校验的列
  1969. * @param notPassedIds 没有通过校验的 id
  1970. * @param update 是否更新到vue中
  1971. * @param validType 校验触发的方式(input、blur等)
  1972. * @param callback
  1973. */
  1974. validateOneInputAsync(value, row, column, notPassedIds, update = false, validType = 'input', callback) {
  1975. let tooltips = Object.assign({}, this.tooltips)
  1976. // let notPassedIds = cloneObject(this.notPassedIds)
  1977. let inputId = column.key + row.id
  1978. tooltips[inputId] = tooltips[inputId] ? tooltips[inputId] : {}
  1979. let [passed, message] = this.validateValue(column, value)
  1980. const nextThen = (res) => {
  1981. let [passed, message] = res
  1982. // !(passed == null && tooltips[inputId].visible != null)
  1983. if (passed != null) {
  1984. tooltips[inputId].visible = !passed
  1985. tooltips[inputId].passed = passed
  1986. let index = notPassedIds.indexOf(inputId)
  1987. let borderColor = null,
  1988. boxShadow = null
  1989. if (!passed) {
  1990. tooltips[inputId].title = this.replaceProps(column, message)
  1991. borderColor = 'red'
  1992. boxShadow = `0 0 0 2px rgba(255, 0, 0, 0.2)`
  1993. if (index === -1) notPassedIds.push(inputId)
  1994. } else {
  1995. if (index !== -1) notPassedIds.splice(index, 1)
  1996. }
  1997. let element = document.getElementById(inputId)
  1998. if (element != null) {
  1999. // select 在 .ant-select-selection 上设置 border-color
  2000. if (column.type === FormTypes.select) {
  2001. element = element.getElementsByClassName('ant-select-selection')[0]
  2002. }
  2003. // jdate 在 input 上设置 border-color
  2004. if (column.type === FormTypes.date || column.type === FormTypes.datetime) {
  2005. element = element.getElementsByTagName('input')[0]
  2006. }
  2007. // upload 在 .ant-upload .ant-btn 上设置 border-color
  2008. if (column.type === FormTypes.upload || column.type === FormTypes.file || column.type === FormTypes.image) {
  2009. element = element.getElementsByClassName('ant-upload')[0].getElementsByClassName('ant-btn')[0]
  2010. }
  2011. element.style.borderColor = borderColor
  2012. element.style.boxShadow = boxShadow
  2013. if (element.tagName === 'SPAN') {
  2014. element.style.display = 'block'
  2015. }
  2016. }
  2017. }
  2018. // 是否更新到data
  2019. if (update) {
  2020. this.tooltips = tooltips
  2021. this.notPassedIds = notPassedIds
  2022. }
  2023. if (typeof callback === 'function') {
  2024. callback([tooltips[inputId], notPassedIds])
  2025. }
  2026. }
  2027. if (typeof passed === 'function') {
  2028. let executed = false
  2029. passed(
  2030. validType,
  2031. value,
  2032. { id: this.getCleanId(row.id) },
  2033. { ...column },
  2034. (flag, msg) => {
  2035. if (executed) return
  2036. executed = true
  2037. if (typeof msg === 'string') {
  2038. message = msg
  2039. }
  2040. if (flag == null) {
  2041. nextThen([null, message])
  2042. } else {
  2043. nextThen([!!flag, message])
  2044. }
  2045. },
  2046. this
  2047. )
  2048. } else {
  2049. nextThen([passed, message])
  2050. }
  2051. return [tooltips[inputId], notPassedIds]
  2052. },
  2053. /** 验证单个表单 */
  2054. validateOneInput(value, row, column, notPassedIds, update = false, validType = 'input') {
  2055. return this.validateOneInputAsync(value, row, column, notPassedIds, update, validType)
  2056. },
  2057. /** 通过规则验证值是否正确 */
  2058. validateValue(column, value) {
  2059. let rules = column.validateRules
  2060. let passed = true,
  2061. message = ''
  2062. // 判断有没有验证规则或验证规则格式正不正确,若条件不符合则默认通过
  2063. if (rules instanceof Array) {
  2064. for (let rule of rules) {
  2065. // 当前值是否为空
  2066. let isNull = value == null || value === ''
  2067. // 验证规则:非空
  2068. if (rule.required === true && isNull) {
  2069. passed = false
  2070. } // 使用 else-if 是为了防止一个 rule 中出现两个规则
  2071. // 验证规则:唯一校验
  2072. else if (rule.unique === true || rule.pattern === 'only') {
  2073. let { values } = this.getValuesSync({ validate: false })
  2074. let findCount = 0
  2075. for (let val of values) {
  2076. if (val[column.key] === value) {
  2077. if (++findCount >= 2) {
  2078. passed = false
  2079. break
  2080. }
  2081. }
  2082. }
  2083. }
  2084. // 验证规则:正则表达式
  2085. else if (!!rule.pattern && !isNull) {
  2086. // 兼容 online 的规则
  2087. let foo = [
  2088. { title: '6到16位数字', value: 'n6-16', pattern: /^\d{6,18}$/ },
  2089. { title: '6到16位任意字符', value: '*6-16', pattern: /^.{6,16}$/ },
  2090. { title: '6到18位字母', value: 's6-18', pattern: /^[a-z|A-Z]{6,18}$/ },
  2091. {
  2092. title: '网址',
  2093. value: 'url',
  2094. pattern:
  2095. /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/,
  2096. },
  2097. { title: '电子邮件', value: 'e', pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/ },
  2098. { title: '手机号码', value: 'm', pattern: /^1[3456789]\d{9}$/ },
  2099. { title: '邮政编码', value: 'p', pattern: /^[1-9]\d{5}$/ },
  2100. { title: '字母', value: 's', pattern: /^[A-Z|a-z]+$/ },
  2101. { title: '数字', value: 'n', pattern: /^-?\d+(\.?\d+|\d?)$/ },
  2102. { title: '整数', value: 'z', pattern: /^-?\d+$/ },
  2103. { title: '非空', value: '*', pattern: /^.+$/ },
  2104. { title: '金额', value: 'money', pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/ },
  2105. ]
  2106. let flag = false
  2107. for (let item of foo) {
  2108. if (rule.pattern === item.value && item.pattern) {
  2109. passed = new RegExp(item.pattern).test(value)
  2110. flag = true
  2111. break
  2112. }
  2113. }
  2114. if (!flag) passed = new RegExp(rule.pattern).test(value)
  2115. }
  2116. // 校验规则:自定义函数校验
  2117. else if (typeof rule.handler === 'function') {
  2118. return [rule.handler, rule.message]
  2119. }
  2120. // 如果没有通过验证,则跳出循环。如果通过了验证,则继续验证下一条规则
  2121. if (!passed) {
  2122. message = rule.message
  2123. break
  2124. }
  2125. }
  2126. }
  2127. return [passed, message]
  2128. },
  2129. /** 动态更新表单的值 */
  2130. updateFormValues() {
  2131. let trs = this.getElement('tbody').getElementsByClassName('tr')
  2132. let trEls = []
  2133. for (let tr of trs) {
  2134. trEls.push(tr)
  2135. }
  2136. // 获取新增的 tr
  2137. let newTrEls = trEls
  2138. if (this.visibleTrEls.length > 0) {
  2139. newTrEls = []
  2140. for (let tr of trEls) {
  2141. let isNewest = true
  2142. for (let vtr of this.visibleTrEls) {
  2143. if (vtr.id === tr.id) {
  2144. isNewest = false
  2145. break
  2146. }
  2147. }
  2148. if (isNewest) {
  2149. newTrEls.push(tr)
  2150. }
  2151. }
  2152. }
  2153. this.visibleTrEls = trEls
  2154. // 向新增的tr中赋值
  2155. newTrEls.forEach((tr) => {
  2156. let { idx } = tr.dataset
  2157. let value = this.inputValues[idx]
  2158. for (let key in value) {
  2159. if (value.hasOwnProperty(key)) {
  2160. let elid = `${key}${value.id}`
  2161. let el = document.getElementById(elid)
  2162. if (el) {
  2163. el.value = value[key]
  2164. }
  2165. }
  2166. }
  2167. })
  2168. },
  2169. /** 强制更新FormValues */
  2170. forceUpdateFormValues() {
  2171. this.visibleTrEls = []
  2172. this.updateFormValues()
  2173. },
  2174. // 重新计算所有统计列
  2175. recalcAllStatisticsColumns() {
  2176. if (this.hasStatisticsColumn) {
  2177. Object.keys(this.statisticsColumns).forEach((key) => this.recalcOneStatisticsColumn(key))
  2178. }
  2179. },
  2180. // 重新计算单个统计列
  2181. recalcOneStatisticsColumn(key) {
  2182. if (this.hasStatisticsColumn) {
  2183. if (this.statisticsColumns.hasOwnProperty(key)) {
  2184. // 计算合计值
  2185. let count = 0
  2186. this.inputValues.forEach((item) => {
  2187. let value = item[key]
  2188. if (value && count !== '-') {
  2189. try {
  2190. count += Number.parseFloat(value)
  2191. } catch (e) {
  2192. count = '-'
  2193. }
  2194. }
  2195. })
  2196. this.statisticsColumns[key] = count.toFixed(2)
  2197. }
  2198. }
  2199. },
  2200. /** 获取某个统计字段的值 */
  2201. getStatisticsValue(key) {
  2202. if (this.hasStatisticsColumn) {
  2203. if (this.statisticsColumns.hasOwnProperty(key)) {
  2204. return this.statisticsColumns[key]
  2205. }
  2206. }
  2207. return null
  2208. },
  2209. /** 全选或取消全选 */
  2210. handleChangeCheckedAll() {
  2211. let selectedRowIds = []
  2212. if (!this.getSelectAll) {
  2213. this.rows.forEach((row) => {
  2214. if ((this.disabledRowIds || []).indexOf(row.id) === -1) {
  2215. selectedRowIds.push(row.id)
  2216. }
  2217. })
  2218. }
  2219. this.selectedRowIds = selectedRowIds
  2220. },
  2221. /** 左侧行选择框change事件 */
  2222. handleChangeLeftCheckbox(event) {
  2223. let { id } = event.target
  2224. if ((this.disabledRowIds || []).indexOf(id) !== -1) {
  2225. return
  2226. }
  2227. let index = this.selectedRowIds.indexOf(id)
  2228. if (index !== -1) {
  2229. this.selectedRowIds.splice(index, 1)
  2230. } else {
  2231. this.selectedRowIds.push(id)
  2232. }
  2233. },
  2234. handleClickAdd() {
  2235. this.add()
  2236. },
  2237. handleConfirmDelete() {
  2238. this.removeSelectedRows()
  2239. },
  2240. handleClickClearSelection() {
  2241. this.clearSelection()
  2242. },
  2243. clearSelection() {
  2244. this.selectedRowIds = []
  2245. },
  2246. /** 用于搜索下拉框中的内容 */
  2247. handleSelectFilterOption(input, option, column) {
  2248. if (column.allowSearch === true || column.allowInput === true) {
  2249. return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  2250. }
  2251. return true
  2252. },
  2253. /** select 搜索时的事件,用于动态添加options */
  2254. handleSearchSelect(value, id, row, col) {
  2255. if (col.allowSearch !== true && col.allowInput === true) {
  2256. // 是否找到了对应的项,找不到则添加这一项
  2257. let flag = false
  2258. for (let option of col.options) {
  2259. if (option.value.toLocaleString() === value.toLocaleString()) {
  2260. flag = true
  2261. break
  2262. }
  2263. }
  2264. // !!value :不添加空值
  2265. if (!flag && !!value) {
  2266. // searchAdd 是否是通过搜索添加的
  2267. col.options.push({ title: value, value: value, searchAdd: true })
  2268. }
  2269. }
  2270. },
  2271. //获取焦点
  2272. handleFocusSearch(value, id, row, col) {
  2273. this.validateOneInput(value, row, col, this.notPassedIds, true, 'focus')
  2274. this.elemValueChange('unit', row, col, value)
  2275. },
  2276. // blur 失去焦点
  2277. handleBlurSearch(value, id, row, col) {
  2278. if (col.allowInput === true) {
  2279. // 删除无用的因搜索(用户输入)而创建的项
  2280. if (typeof value === 'string') {
  2281. let indexs = []
  2282. col.options.forEach((option, index) => {
  2283. if (option.value.toLocaleString() === value.toLocaleString()) {
  2284. delete option.searchAdd
  2285. } else if (option.searchAdd === true) {
  2286. indexs.push(index)
  2287. }
  2288. })
  2289. // 翻转删除数组中的项
  2290. for (let index of indexs.reverse()) {
  2291. col.options.splice(index, 1)
  2292. }
  2293. }
  2294. }
  2295. // 做单个表单验证
  2296. this.validateOneInput(value, row, col, this.notPassedIds, true, 'blur')
  2297. },
  2298. /** 触发已拖动事件 */
  2299. emitDragged(oldIndex, newIndex) {
  2300. this.$emit('dragged', { oldIndex, newIndex, target: this })
  2301. },
  2302. handleDragMoveStart(event) {
  2303. this.dragging = true
  2304. this.$refs.scrollView.style.overflow = 'hidden'
  2305. },
  2306. /** 拖动结束,交换inputValue中的值 */
  2307. handleDragMoveEnd(event) {
  2308. this.dragging = false
  2309. this.$refs.scrollView.style.overflow = 'auto'
  2310. let {
  2311. oldIndex,
  2312. newIndex,
  2313. item: {
  2314. dataset: { idx: dataIdx },
  2315. },
  2316. } = event
  2317. // 由于动态显示隐藏行导致index有误差,需要算出真实的index
  2318. let diff = Number.parseInt(dataIdx) - oldIndex
  2319. oldIndex += diff
  2320. newIndex += diff
  2321. this.rowResort(oldIndex, newIndex)
  2322. this.emitDragged(oldIndex, newIndex)
  2323. },
  2324. /** 行重新排序 */
  2325. rowResort(oldIndex, newIndex) {
  2326. const sort = (array) => {
  2327. // 存储旧数据,并删除旧项目
  2328. let temp = array[oldIndex]
  2329. array.splice(oldIndex, 1)
  2330. // 向新项目里添加旧数据
  2331. array.splice(newIndex, 0, temp)
  2332. }
  2333. sort(this.rows)
  2334. sort(this.inputValues)
  2335. this.recalcSortNumber()
  2336. this.forceUpdateFormValues()
  2337. },
  2338. /** 重新计算排序字段的数值 */
  2339. recalcSortNumber() {
  2340. if (this.dragSort) {
  2341. // 重置排序字段
  2342. this.inputValues.forEach((val, idx) => (val[this.dragSortKey] = idx + 1))
  2343. }
  2344. },
  2345. /** 当前行向上移一位 */
  2346. _handleRowMoveUp(rowIndex) {
  2347. if (rowIndex > 0) {
  2348. let newIndex = rowIndex - 1
  2349. this.rowResort(rowIndex, newIndex)
  2350. this.emitDragged(rowIndex, newIndex)
  2351. }
  2352. },
  2353. /** 当前行向下移一位 */
  2354. _handleRowMoveDown(rowIndex) {
  2355. if (rowIndex < this.rows.length - 1) {
  2356. let newIndex = rowIndex + 1
  2357. this.rowResort(rowIndex, newIndex)
  2358. this.emitDragged(rowIndex, newIndex)
  2359. }
  2360. },
  2361. /** 在当前行下面插入一行 */
  2362. _handleRowInsertDown(rowIndex) {
  2363. let insertIndex = rowIndex + 1
  2364. this.insert(insertIndex)
  2365. },
  2366. /* --- common function begin --- */
  2367. /** 鼠标移入 */
  2368. handleMouseoverCommono(row, column) {
  2369. let inputId = column.key + row.id
  2370. if (this.notPassedIds.indexOf(inputId) !== -1) {
  2371. this.showOrHideTooltip(inputId, true, true)
  2372. }
  2373. },
  2374. /** 鼠标移出 */
  2375. handleMouseoutCommono(row, column) {
  2376. let inputId = column.key + row.id
  2377. this.showOrHideTooltip(inputId, false)
  2378. },
  2379. /** input事件 */
  2380. handleInputCommono(target, index, row, column) {
  2381. let oldValue = this.inputValues[index][column.key] || ''
  2382. let { value, dataset, selectionStart } = target
  2383. let type = FormTypes.input
  2384. let change = true
  2385. if (`${dataset.inputNumber}` === 'true') {
  2386. type = FormTypes.inputNumber
  2387. // 判断输入的值是否匹配数字正则表达式,不匹配就还原
  2388. if (!/^-?\d+\.?\d*$/.test(value) && value !== '' && value !== '-') {
  2389. change = false
  2390. value = oldValue
  2391. target.value = value
  2392. if (typeof selectionStart === 'number') {
  2393. target.selectionStart = selectionStart - 1
  2394. target.selectionEnd = selectionStart - 1
  2395. }
  2396. }
  2397. }
  2398. // 存储输入的值
  2399. this.inputValues[index][column.key] = value
  2400. // 做单个表单验证
  2401. this.validateOneInput(value, row, column, this.notPassedIds, true, 'input')
  2402. if (type === FormTypes.inputNumber) {
  2403. this.recalcOneStatisticsColumn(column.key)
  2404. }
  2405. // 触发valueChange 事件
  2406. if (change) {
  2407. this.elemValueChange(type, row, column, value)
  2408. }
  2409. },
  2410. /** slot Change */
  2411. handleChangeSlotCommon(value, id, row, column) {
  2412. this.slotValues = this.bindValuesChange(value, id, 'slotValues')
  2413. // 做单个表单验证
  2414. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2415. // 触发valueChange 事件
  2416. this.elemValueChange(FormTypes.slot, row, column, value)
  2417. },
  2418. handleFocusSlotCommon(value, id, row, column) {
  2419. // this.slotValues = this.bindValuesChange(value, id, 'slotValues')
  2420. // // 做单个表单验证
  2421. this.validateOneInput(value, row, column, this.notPassedIds, true, 'focus')
  2422. // // 触发valueChange 事件
  2423. this.elemFocusChange(FormTypes.slot, row, column, value)
  2424. },
  2425. //获取焦点时触发
  2426. elemFocusChange(type, rowSource, columnSource, value) {
  2427. let unitList = []
  2428. let column = Object.assign({}, columnSource)
  2429. // 将caseId去除
  2430. let row = Object.assign({}, rowSource)
  2431. row.id = this.getCleanId(row.id)
  2432. // 获取整行的数据
  2433. let { values } = this.getValuesSync({ validate: false, rowIds: [row.id] })
  2434. if (values.length > 0) {
  2435. Object.assign(row, values[0])
  2436. }
  2437. if (!row.unitId) {
  2438. unitList = []
  2439. }
  2440. let arr = row.unitList
  2441. if (arr && !Array.isArray(arr)) {
  2442. unitList = JSON.parse(arr)
  2443. }
  2444. column.options = unitList
  2445. this.$emit('focusChange', unitList)
  2446. },
  2447. handleBlurCommono(target, index, row, column) {
  2448. let { value, dataset } = target
  2449. if (dataset && `${dataset.inputNumber}` === 'true') {
  2450. // 判断输入的值是否匹配数字正则表达式,不匹配就置空
  2451. if (!/^-?\d+\.?\d*$/.test(value)) {
  2452. value = ''
  2453. } else {
  2454. value = Number.parseFloat(value)
  2455. }
  2456. target.value = value
  2457. }
  2458. // 做单个表单验证
  2459. this.validateOneInput(value, row, column, this.notPassedIds, true, 'blur')
  2460. },
  2461. handleChangeCheckboxCommon(event, row, column) {
  2462. let { id, checked } = event.target
  2463. this.checkboxValues = this.bindValuesChange(checked, id, 'checkboxValues')
  2464. // 触发valueChange 事件
  2465. this.elemValueChange(FormTypes.checkbox, row, column, checked)
  2466. },
  2467. handleChangeSelectCommon(value, id, row, column) {
  2468. this.selectValues = this.bindValuesChange(value, id, 'selectValues')
  2469. // 做单个表单验证
  2470. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2471. // 触发valueChange 事件
  2472. this.elemValueChange(FormTypes.select, row, column, value)
  2473. },
  2474. handleChangePopupJshCommon(value, id, row, column, index) {
  2475. this.popupJshValues = this.bindValuesChange(value, id, 'popupJshValues')
  2476. // 做单个表单验证
  2477. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2478. // 触发valueChange 事件
  2479. this.elemValueChange(FormTypes.popupJsh, row, column, value)
  2480. },
  2481. handleChangeJDateCommon(value, id, row, column, showTime) {
  2482. this.jdateValues = this.bindValuesChange(value, id, 'jdateValues')
  2483. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2484. // 触发valueChange 事件
  2485. if (showTime) {
  2486. this.elemValueChange(FormTypes.datetime, row, column, value)
  2487. } else {
  2488. this.elemValueChange(FormTypes.date, row, column, value)
  2489. }
  2490. },
  2491. handleChangeJInputPopCommon(value, id, row, column) {
  2492. this.jInputPopValues = this.bindValuesChange(value, id, 'jInputPopValues')
  2493. // 做单个表单验证
  2494. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2495. // 触发valueChange 事件
  2496. this.elemValueChange(FormTypes.input_pop, row, column, value)
  2497. },
  2498. handleChangeUpload(info, id, row, column) {
  2499. let { file } = info
  2500. let value = {
  2501. name: file.name,
  2502. type: file.type,
  2503. size: file.size,
  2504. status: file.status,
  2505. percent: file.percent,
  2506. }
  2507. if (column.responseName && file.response) {
  2508. value['responseName'] = file.response[column.responseName]
  2509. }
  2510. if (file.status === 'done') {
  2511. value['path'] = file.response[column.responseName]
  2512. } else if (file.status === 'error') {
  2513. value['message'] = file.response.message || '未知错误'
  2514. }
  2515. this.uploadValues = this.bindValuesChange(value, id, 'uploadValues')
  2516. },
  2517. handleMoreOperation(id, flag) {
  2518. //console.log("this.uploadValues[id]",this.uploadValues[id])
  2519. let path = ''
  2520. if (this.uploadValues && this.uploadValues[id]) {
  2521. path = this.uploadValues[id].path
  2522. }
  2523. this.$refs.filePop.show(id, path, flag)
  2524. },
  2525. handleFileSuccess(obj) {
  2526. if (obj.id) {
  2527. this.uploadValues = this.bindValuesChange(obj, obj.id, 'uploadValues')
  2528. }
  2529. },
  2530. /** 记录用到数据绑定的组件的值 */
  2531. bindValuesChange(value, id, key) {
  2532. // let values = Object.assign({}, this[key])
  2533. // values[id] = value
  2534. // return values
  2535. this.$set(this[key], id, value)
  2536. return this[key]
  2537. },
  2538. /** 显示或隐藏tooltip */
  2539. showOrHideTooltip(inputId, show, force = false) {
  2540. if (!this.tooltips[inputId] && !force) {
  2541. return
  2542. }
  2543. let tooltip = this.tooltips[inputId] || {}
  2544. if (tooltip.visible !== show) {
  2545. tooltip.visible = show
  2546. this.$set(this.tooltips, inputId, tooltip)
  2547. }
  2548. },
  2549. /** value 触发valueChange事件 */
  2550. elemValueChange(type, rowSource, columnSource, value) {
  2551. let column = Object.assign({}, columnSource)
  2552. // 将caseId去除
  2553. let row = Object.assign({}, rowSource)
  2554. row.id = this.getCleanId(row.id)
  2555. // 获取整行的数据
  2556. let { values } = this.getValuesSync({ validate: false, rowIds: [row.id] })
  2557. if (values.length > 0) {
  2558. Object.assign(row, values[0])
  2559. }
  2560. this.$emit('valueChange', { type, row, column, value, target: this })
  2561. },
  2562. /** 获取干净的ID(不包含任何杂质的ID) */
  2563. getCleanId(id) {
  2564. id = this.removeCaseId(id)
  2565. id = this.removeTempId(id)
  2566. return id
  2567. },
  2568. /** 判断某个ID是否包含了caseId */
  2569. hasCaseId(id) {
  2570. id = id + ''
  2571. return id && id.startsWith(this.caseId)
  2572. },
  2573. /** 将caseId去除 */
  2574. removeCaseId(id) {
  2575. if (this.hasCaseId(id)) {
  2576. return id.substring(this.caseId.length, id.length)
  2577. }
  2578. return id
  2579. },
  2580. // 判断 id 是否是临时Id
  2581. isTempId(id) {
  2582. return (id || '').endsWith(this.tempId)
  2583. },
  2584. /** 将tempId去除 */
  2585. removeTempId(id) {
  2586. if (this.isTempId(id)) {
  2587. return id.substring(0, id.length - this.tempId.length)
  2588. }
  2589. return id
  2590. },
  2591. handleClickDelFile(id) {
  2592. this.uploadValues[id] = null
  2593. },
  2594. handleClickDownloadFile(id) {
  2595. let { path } = this.uploadValues[id] || {}
  2596. if (path) {
  2597. let url = getFileAccessHttpUrl(path)
  2598. window.open(url)
  2599. }
  2600. },
  2601. handleClickDownFileByUrl(id) {
  2602. let { url, path } = this.uploadValues[id] || {}
  2603. if (!url || url.length === 0) {
  2604. if (path && path.length > 0) {
  2605. url = getFileAccessHttpUrl(path.split(',')[0])
  2606. }
  2607. }
  2608. if (url) {
  2609. window.open(url)
  2610. }
  2611. },
  2612. handleClickShowImageError(id) {
  2613. let currUploadObj = this.uploadValues[id] || null
  2614. if (currUploadObj && currUploadObj['message']) {
  2615. this.$error({ title: '上传出错', content: '错误信息:' + currUploadObj['message'], maskClosable: true })
  2616. }
  2617. },
  2618. /* --- common function end --- */
  2619. /* --- 以下是辅助方法,多用于动态构造页面中的数据 --- */
  2620. /** 辅助方法:打印日志 */
  2621. log() {
  2622. if (this.$attrs.logger) {
  2623. console.log.apply(null, arguments)
  2624. }
  2625. },
  2626. getVM() {
  2627. return this
  2628. },
  2629. /** 辅助方法:指定a-select 和 j-data 的父容器 */
  2630. getParentContainer(node) {
  2631. let element = (() => {
  2632. // nodeType 8 : Comment : 注释
  2633. if (this.$el && this.$el.nodeType !== 8) {
  2634. return this.$el
  2635. }
  2636. let doc = document.getElementById(this.caseId + 'inputTable')
  2637. if (doc != null) {
  2638. return doc
  2639. }
  2640. return node.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
  2641. })()
  2642. // 递归判断是否带有 overflow: hidden;的父元素
  2643. const ifParent = (child) => {
  2644. let currentOverflow = null
  2645. if (child['currentStyle']) {
  2646. currentOverflow = child['currentStyle']['overflow']
  2647. } else if (window.getComputedStyle) {
  2648. currentOverflow = window.getComputedStyle(child)['overflow']
  2649. }
  2650. if (currentOverflow != null) {
  2651. if (currentOverflow === 'hidden') {
  2652. // 找到了带有 hidden 的标签,判断它的父级是否还有 hidden,直到遇到完全没有 hidden 或 body 的时候才停止递归
  2653. let temp = ifParent(child.parentNode)
  2654. return temp != null ? temp : child.parentNode
  2655. }
  2656. // 当前标签没有 hidden ,如果有父级并且父级不是 body 的话就继续递归判断父级
  2657. else if (child.parentNode && child.parentNode.tagName.toLocaleLowerCase() !== 'body') {
  2658. return ifParent(child.parentNode)
  2659. } else {
  2660. // 直到 body 都没有遇到有 hidden 的标签
  2661. return null
  2662. }
  2663. } else {
  2664. return child
  2665. }
  2666. }
  2667. let temp = ifParent(element)
  2668. return temp != null ? temp : element
  2669. },
  2670. /** 辅助方法:替换${...}变量 */
  2671. replaceProps(col, value) {
  2672. if (value && typeof value === 'string') {
  2673. value = value.replace(/\${title}/g, col.title)
  2674. value = value.replace(/\${key}/g, col.key)
  2675. value = value.replace(/\${defaultValue}/g, col.defaultValue)
  2676. }
  2677. return value
  2678. },
  2679. /** view辅助方法:构建 tr style */
  2680. buildTrStyle(index) {
  2681. return {
  2682. top: `${rowHeight * index}px`,
  2683. }
  2684. },
  2685. /** view辅助方法:构建 td style */
  2686. buildTdStyle(col) {
  2687. const isEmptyWidth = (column) =>
  2688. column.type === FormTypes.hidden || column.width === '0px' || column.width === '0' || column.width === 0
  2689. let style = {}
  2690. // 计算宽度
  2691. if (col.width) {
  2692. style['width'] = col.width
  2693. } else if (this.columns) {
  2694. style['width'] = `${(100 - 4 * 2) / this.columns.filter((column) => !isEmptyWidth(column)).length}%`
  2695. } else {
  2696. style['width'] = '120px'
  2697. }
  2698. // checkbox 居中显示
  2699. let isCheckbox = col.type === FormTypes.checkbox
  2700. if (isCheckbox) {
  2701. style['align-items'] = 'center'
  2702. style['text-align'] = 'center'
  2703. style['padding-left'] = '0'
  2704. style['padding-right'] = '0'
  2705. }
  2706. if (isEmptyWidth(col)) {
  2707. style['padding-left'] = '0'
  2708. style['padding-right'] = '0'
  2709. }
  2710. style['box-sizing'] = 'border-box'
  2711. return style
  2712. },
  2713. /** view辅助方法:构造props */
  2714. buildProps(row, col) {
  2715. let props = {}
  2716. // 解析props
  2717. if (typeof col.props === 'object') {
  2718. for (let prop in col.props) {
  2719. if (col.props.hasOwnProperty(prop)) {
  2720. props[prop] = this.replaceProps(col, col.props[prop])
  2721. }
  2722. }
  2723. }
  2724. // 判断select是否允许输入
  2725. if (col.type === FormTypes.select && (col.allowInput === true || col.allowSearch === true)) {
  2726. props['showSearch'] = true
  2727. }
  2728. // 判断是否是禁用的列
  2729. props['disabled'] = typeof col['disabled'] === 'boolean' ? col['disabled'] : props['disabled']
  2730. // 判断是否为禁用的行
  2731. if (props['disabled'] !== true) {
  2732. props['disabled'] = (this.disabledRowIds || []).indexOf(row.id) !== -1
  2733. }
  2734. // 判断是否禁用全部组件
  2735. if (this.disabled === true) {
  2736. props['disabled'] = true
  2737. }
  2738. return props
  2739. },
  2740. /** upload 辅助方法:获取 headers */
  2741. uploadGetHeaders(row, column) {
  2742. let headers = {}
  2743. if (column.token === true) {
  2744. headers['X-Access-Token'] = this.accessToken
  2745. }
  2746. return headers
  2747. },
  2748. /** 上传请求地址 */
  2749. getUploadAction(value) {
  2750. if (!value) {
  2751. return window._CONFIG['domianURL'] + '/sys/common/upload'
  2752. } else {
  2753. return value
  2754. }
  2755. },
  2756. /** 预览图片地址 */
  2757. getCellImageView(id) {
  2758. let currUploadObj = this.uploadValues[id] || null
  2759. if (currUploadObj) {
  2760. if (currUploadObj['url']) {
  2761. return currUploadObj['url']
  2762. } else if (currUploadObj['path']) {
  2763. let readpath = currUploadObj['path'].split(',')[0]
  2764. return getFileAccessHttpUrl(readpath)
  2765. }
  2766. }
  2767. return ''
  2768. },
  2769. /** popup回调 */
  2770. popupCallback(value, others, id, row, column, index) {
  2771. // 存储输入的值
  2772. this.popupValues[id] = value
  2773. if (others) {
  2774. Object.keys(others).map((key) => {
  2775. this.columns.map((k) => {
  2776. if (k.key === key) {
  2777. let tempId = id.substring(id.indexOf(this.caseIdPrefix))
  2778. if (k.type === 'date') {
  2779. this.handleChangeJDateCommon(others[key], key + tempId, { id: tempId }, k, false)
  2780. } else if (k.type === 'datetime') {
  2781. this.handleChangeJDateCommon(others[key], key + tempId, { id: tempId }, k, true)
  2782. } else {
  2783. this.inputValues[index][key] = others[key]
  2784. }
  2785. }
  2786. })
  2787. })
  2788. }
  2789. // 做单个表单验证
  2790. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2791. // 触发valueChange 事件
  2792. this.elemValueChange('input', row, column, value)
  2793. // 更新form表单的值
  2794. this.$nextTick(() => {
  2795. this.forceUpdateFormValues()
  2796. })
  2797. },
  2798. /** popupJsh回调 */
  2799. popupJshCallback(value, others, id, row, column, index) {
  2800. // 存储输入的值
  2801. this.popupJshValues[id] = value
  2802. if (others) {
  2803. Object.keys(others).map((key) => {
  2804. this.columns.map((k) => {
  2805. if (k.key === key) {
  2806. let tempId = id.substring(id.indexOf(this.caseIdPrefix))
  2807. if (k.type === 'date') {
  2808. this.handleChangeJDateCommon(others[key], key + tempId, { id: tempId }, k, false)
  2809. } else if (k.type === 'datetime') {
  2810. this.handleChangeJDateCommon(others[key], key + tempId, { id: tempId }, k, true)
  2811. } else {
  2812. this.popupJshValues[index][key] = others[key]
  2813. }
  2814. }
  2815. })
  2816. })
  2817. }
  2818. // 做单个表单验证
  2819. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2820. // 触发valueChange 事件
  2821. this.elemValueChange('input', row, column, value)
  2822. // 更新form表单的值
  2823. this.$nextTick(() => {
  2824. this.forceUpdateFormValues()
  2825. })
  2826. },
  2827. /** select输入框回显 */
  2828. getSelectValue(id) {
  2829. return this.selectValues[id]
  2830. },
  2831. /** popup输入框回显 */
  2832. getPopupValue(id) {
  2833. return this.popupValues[id]
  2834. },
  2835. /** popupJsh输入框回显 */
  2836. getPopupJshValue(id) {
  2837. return this.popupJshValues[id]
  2838. },
  2839. /** popupJsh构造传值 */
  2840. getPopupJshRows(row) {
  2841. let { values } = this.getValuesSync({ validate: false, rowIds: [row.id] })
  2842. return JSON.stringify(values[0])
  2843. },
  2844. handleRadioChange(value, id, row, column) {
  2845. this.radioValues = this.bindValuesChange(value, id, 'radioValues')
  2846. // 做单个表单验证
  2847. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2848. // 触发valueChange 事件
  2849. this.elemValueChange(FormTypes.radio, row, column, value)
  2850. },
  2851. handleMultiSelectChange(value, id, row, column) {
  2852. this.multiSelectValues = this.bindValuesChange(value, id, 'multiSelectValues')
  2853. // 做单个表单验证
  2854. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2855. // 触发valueChange 事件
  2856. this.elemValueChange(FormTypes.list_multi, row, column, value)
  2857. },
  2858. handleSearchSelectChange(value, id, row, column) {
  2859. this.searchSelectValues = this.bindValuesChange(value, id, 'searchSelectValues')
  2860. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2861. this.elemValueChange(FormTypes.sel_search, row, column, value)
  2862. },
  2863. filterOption(input, option) {
  2864. return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  2865. },
  2866. getEllipsisWord(content, len) {
  2867. if (!content || content.length == 0) {
  2868. return ''
  2869. }
  2870. if (content.length > len) {
  2871. return content.substr(0, len)
  2872. }
  2873. return content
  2874. },
  2875. /** 回车后自动跳到下一个input **/
  2876. autoJumpNextInputBill() {
  2877. let that = this
  2878. let inputDom = $('.ant-modal-cust-warp:visible').find('#billModal')
  2879. inputDom
  2880. .find('input:visible:not(:checkbox)')
  2881. .off('keydown')
  2882. .on('keydown', function (e) {
  2883. //响应回车键按下的处理
  2884. e = event || window.event || arguments.callee.caller.arguments[0]
  2885. //捕捉是否按键为回车键,可百度JS键盘事件了解更多
  2886. if (e && e.keyCode == 13) {
  2887. //捕捉inputDom下的文本输入框的个数
  2888. let inputs = inputDom.find('input:visible:not(:checkbox)')
  2889. let idx = inputs.index(this) // 获取当前焦点输入框所处的位置
  2890. if (idx == inputs.length - 1) {
  2891. // 判断是否是最后一个输入框
  2892. let curKey = e.which
  2893. if (curKey == 13) {
  2894. //新增行
  2895. that.handleClickAdd()
  2896. //进行下一行的自动聚焦
  2897. setTimeout(function () {
  2898. inputs = inputDom.find('input:visible:not(:checkbox)')
  2899. inputs[idx + 1].focus() // 设置焦点
  2900. inputs[idx + 1].select() // 选中文字
  2901. }, 100)
  2902. }
  2903. } else {
  2904. inputs[idx + 1].focus() // 设置焦点
  2905. inputs[idx + 1].select() // 选中文字
  2906. }
  2907. }
  2908. })
  2909. },
  2910. /** 自动选中特殊的key **/
  2911. autoSelectBySpecialKey(specialKey, orderNum) {
  2912. let trs = this.getElement('tbody').getElementsByClassName('tr')
  2913. let trEls = []
  2914. if (trs && trs.length && orderNum >= 1) {
  2915. trEls.push(trs[orderNum - 1])
  2916. }
  2917. trEls.forEach((tr) => {
  2918. let { idx } = tr.dataset
  2919. let value = this.inputValues[idx]
  2920. for (let key in value) {
  2921. if (value.hasOwnProperty(key)) {
  2922. let elid = `${key}${value.id}`
  2923. let el = document.getElementById(elid)
  2924. if (el && key === specialKey) {
  2925. el.select()
  2926. }
  2927. }
  2928. }
  2929. })
  2930. },
  2931. },
  2932. beforeDestroy() {
  2933. this.destroyCleanGroupRequest = true
  2934. },
  2935. }
  2936. </script>
  2937. <style lang="less" scoped>
  2938. .action-button {
  2939. margin-bottom: 8px;
  2940. .gap {
  2941. padding-left: 8px;
  2942. }
  2943. }
  2944. /* 设定边框参数 */
  2945. @borderColor: #e8e8e8;
  2946. @border: 1px solid @borderColor;
  2947. /* tr & td 之间的间距 */
  2948. @spacing: 2px;
  2949. .input-table {
  2950. max-width: 100%;
  2951. overflow-x: hidden;
  2952. overflow-y: hidden;
  2953. position: relative;
  2954. border: @border;
  2955. .thead,
  2956. .tbody {
  2957. .tr,
  2958. .td {
  2959. display: flex;
  2960. }
  2961. .td {
  2962. /*border-right: 1px solid red;*/
  2963. /*color: white;*/
  2964. /*background-color: black;*/
  2965. /*margin-right: @spacing !important;*/
  2966. padding-left: @spacing;
  2967. flex-direction: column;
  2968. &.td-cb,
  2969. &.td-num {
  2970. min-width: 4%;
  2971. max-width: 45px;
  2972. margin-right: 0;
  2973. padding-left: 0;
  2974. padding-right: 0;
  2975. justify-content: center;
  2976. align-items: center;
  2977. }
  2978. &.td-ds {
  2979. margin-right: 0;
  2980. padding-left: 0;
  2981. padding-right: 0;
  2982. justify-content: center;
  2983. align-items: center;
  2984. .td-ds-icons {
  2985. position: relative;
  2986. cursor: move;
  2987. width: 100%;
  2988. /*padding: 25% 0;*/
  2989. height: 100%;
  2990. .anticon-align-left,
  2991. .anticon-align-right {
  2992. position: absolute;
  2993. top: 30%;
  2994. }
  2995. .anticon-align-left {
  2996. left: 25%;
  2997. }
  2998. .anticon-align-right {
  2999. right: 25%;
  3000. }
  3001. }
  3002. }
  3003. }
  3004. }
  3005. .thead {
  3006. overflow-y: scroll;
  3007. overflow-x: hidden;
  3008. border-bottom: @border;
  3009. /** 隐藏thead的滑块 */
  3010. &::-webkit-scrollbar-thumb {
  3011. box-shadow: none !important;
  3012. background-color: transparent !important;
  3013. }
  3014. .tr {
  3015. min-width: 100%;
  3016. overflow-y: scroll;
  3017. }
  3018. .td {
  3019. /*flex: 1;*/
  3020. padding: 8px @spacing;
  3021. justify-content: center;
  3022. }
  3023. }
  3024. .tbody {
  3025. position: relative;
  3026. top: 0;
  3027. left: 0;
  3028. overflow-x: hidden;
  3029. overflow-y: hidden;
  3030. min-height: 61px;
  3031. /*max-height: 400px;*/
  3032. min-width: 100%;
  3033. .tr-nodata {
  3034. color: #999;
  3035. line-height: 61px;
  3036. text-align: center;
  3037. }
  3038. .tr {
  3039. /*line-height: 50px;*/
  3040. border-bottom: @border;
  3041. transition: background-color 300ms;
  3042. width: 100%;
  3043. position: absolute;
  3044. left: 0;
  3045. z-index: 10;
  3046. &.tr-checked {
  3047. background-color: #fafafa;
  3048. }
  3049. &:hover {
  3050. background-color: #e6f7ff;
  3051. }
  3052. }
  3053. .tr-expand {
  3054. position: relative;
  3055. z-index: 9;
  3056. background-color: white;
  3057. }
  3058. .td {
  3059. /*flex: 1;*/
  3060. padding: 6px @spacing 6px 0;
  3061. justify-content: center;
  3062. &:last-child {
  3063. padding-right: @spacing;
  3064. }
  3065. input {
  3066. font-variant: tabular-nums;
  3067. box-sizing: border-box;
  3068. margin: 0;
  3069. list-style: none;
  3070. position: relative;
  3071. display: inline-block;
  3072. padding: 2px 2px;
  3073. width: 100%;
  3074. height: 32px;
  3075. font-size: 14px;
  3076. line-height: 1.5;
  3077. color: rgba(0, 0, 0, 0.65);
  3078. background-color: #fff;
  3079. border: 1px solid #d9d9d9;
  3080. border-radius: 4px;
  3081. transition: all 0.3s;
  3082. outline: none;
  3083. &:hover {
  3084. border-color: #4d90fe;
  3085. }
  3086. &:focus {
  3087. border-color: #40a9ff;
  3088. box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
  3089. border-right-width: 1px !important;
  3090. }
  3091. &:disabled {
  3092. color: rgba(0, 0, 0, 0.25);
  3093. background: #f5f5f5;
  3094. cursor: not-allowed;
  3095. }
  3096. /* 设置placeholder的颜色 */
  3097. &::-webkit-input-placeholder {
  3098. /* WebKit browsers */
  3099. color: #ccc;
  3100. }
  3101. &:-moz-placeholder {
  3102. /* Mozilla Firefox 4 to 18 */
  3103. color: #ccc;
  3104. }
  3105. &::-moz-placeholder {
  3106. /* Mozilla Firefox 19+ */
  3107. color: #ccc;
  3108. }
  3109. &:-ms-input-placeholder {
  3110. /* Internet Explorer 10+ */
  3111. color: #ccc;
  3112. }
  3113. }
  3114. .j-editable-image {
  3115. height: 32px;
  3116. max-width: 100px !important;
  3117. cursor: pointer;
  3118. &:hover {
  3119. opacity: 0.8;
  3120. }
  3121. &:active {
  3122. opacity: 0.6;
  3123. }
  3124. }
  3125. .td-span {
  3126. font-variant: tabular-nums;
  3127. box-sizing: border-box;
  3128. margin: 0;
  3129. list-style: none;
  3130. position: relative;
  3131. display: inline-block;
  3132. padding: 2px 2px;
  3133. width: 100%;
  3134. height: 32px;
  3135. font-size: 14px;
  3136. line-height: 1.9;
  3137. color: rgba(0, 0, 0, 0.65);
  3138. background-color: #fff;
  3139. border: 1px dashed #d9d9d9;
  3140. border-radius: 4px;
  3141. transition: all 0.3s;
  3142. outline: none;
  3143. overflow: hidden;
  3144. // white-space: nowrap;
  3145. text-overflow: ellipsis;
  3146. // flex-shrink: 0;
  3147. // max-width: 150px;
  3148. }
  3149. }
  3150. }
  3151. .scroll-view {
  3152. overflow: auto;
  3153. overflow-y: scroll;
  3154. }
  3155. .thead,
  3156. .thead .tr,
  3157. .scroll-view {
  3158. @scrollBarSize: 6px;
  3159. /* 定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
  3160. &::-webkit-scrollbar {
  3161. width: @scrollBarSize;
  3162. height: @scrollBarSize;
  3163. background-color: transparent;
  3164. }
  3165. /* 定义滚动条轨道 */
  3166. &::-webkit-scrollbar-track {
  3167. background-color: #f0f0f0;
  3168. }
  3169. /* 定义滑块 */
  3170. &::-webkit-scrollbar-thumb {
  3171. background-color: #eee;
  3172. box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
  3173. &:hover {
  3174. background-color: #bbb;
  3175. }
  3176. &:active {
  3177. background-color: #888;
  3178. }
  3179. }
  3180. }
  3181. .thead .tr {
  3182. &::-webkit-scrollbar-track {
  3183. background-color: transparent;
  3184. }
  3185. /* IE模式下隐藏 */
  3186. -ms-overflow-style: none;
  3187. -ms-scroll-chaining: chained;
  3188. -ms-content-zooming: zoom;
  3189. -ms-scroll-rails: none;
  3190. -ms-content-zoom-limit-min: 100%;
  3191. -ms-content-zoom-limit-max: 500%;
  3192. -ms-scroll-snap-type: proximity;
  3193. -ms-scroll-snap-points-x: snapList(100%, 200%, 300%, 400%, 500%);
  3194. }
  3195. }
  3196. </style>