JEditableTable.vue 118 KB

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