uni-data-picker.uvue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <view class="uni-data-tree">
  3. <view class="uni-data-tree-input" @click="handleInput">
  4. <slot :data="selectedPaths" :error="error">
  5. <view class="input-value" :class="{'input-value-border': border}">
  6. <text v-if="error!=null" class="error-text">{{error!.errMsg}}</text>
  7. <scroll-view v-if="selectedPaths.length" class="selected-path" scroll-x="true">
  8. <view class="selected-list">
  9. <template v-for="(item, index) in selectedPaths">
  10. <text class="text-color">{{item[mappingTextName]}}</text>
  11. <text v-if="index<selectedPaths.length-1" class="input-split-line">{{split}}</text>
  12. </template>
  13. </view>
  14. </scroll-view>
  15. <text v-else-if="error==null&&!loading" class="placeholder">{{placeholder}}</text>
  16. <view v-if="!readonly" class="arrow-area">
  17. <view class="input-arrow"></view>
  18. </view>
  19. </view>
  20. </slot>
  21. <view v-if="loading && !isOpened" class="selected-loading">
  22. <slot name="picker-loading" :loading="loading"></slot>
  23. </view>
  24. </view>
  25. <view class="uni-data-tree-cover" v-if="isOpened" @click="handleClose"></view>
  26. <view class="uni-data-tree-dialog" v-if="isOpened">
  27. <view class="uni-popper__arrow"></view>
  28. <view class="dialog-caption">
  29. <view class="dialog-title-view">
  30. <text class="dialog-title">{{popupTitle}}</text>
  31. </view>
  32. <view class="dialog-close" @click="handleClose">
  33. <view class="dialog-close-plus" data-id="close"></view>
  34. <view class="dialog-close-plus dialog-close-rotate" data-id="close"></view>
  35. </view>
  36. </view>
  37. <view ref="pickerView" class="uni-data-pickerview">
  38. <view v-if="error!=null" class="error">
  39. <text class="error-text">{{error!.errMsg}}</text>
  40. </view>
  41. <scroll-view v-if="!isCloudDataList" :scroll-x="true">
  42. <view class="selected-node-list">
  43. <template v-for="(item, index) in selectedNodes">
  44. <text class="selected-node-item" :class="{'selected-node-item-active':index==selectedIndex}"
  45. @click="onTabSelect(index)">
  46. {{item[mappingTextName]}}
  47. </text>
  48. </template>
  49. </view>
  50. </scroll-view>
  51. <list-view class="list-view" :scroll-y="true">
  52. <list-item class="list-item" v-for="(item, _) in currentDataList" @click="onNodeClick(item)">
  53. <text class="item-text" :class="{'item-text-disabled': item['disable']}">{{item[mappingTextName]}}</text>
  54. <text class="check" v-if="item[mappingValueName] == selectedNodes[selectedIndex][mappingValueName]"></text>
  55. </list-item>
  56. </list-view>
  57. <view class="loading-cover" v-if="loading">
  58. <slot name="pickerview-loading" :loading="loading"></slot>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. import { dataPicker } from "../uni-data-pickerview/uni-data-picker.uts"
  66. /**
  67. * DataPicker 级联选择
  68. * @description 支持单列、和多列级联选择。列数没有限制,如果屏幕显示不全,顶部tab区域会左右滚动。
  69. * @tutorial https://ext.dcloud.net.cn/plugin?id=3796
  70. * @property {String} popup-title 弹出窗口标题
  71. * @property {Array} localdata 本地数据,参考
  72. * @property {Boolean} border = [true|false] 是否有边框
  73. * @property {Boolean} readonly = [true|false] 是否仅读
  74. * @property {Boolean} preload = [true|false] 是否预加载数据
  75. * @value true 开启预加载数据,点击弹出窗口后显示已加载数据
  76. * @value false 关闭预加载数据,点击弹出窗口后开始加载数据
  77. * @property {Boolean} step-searh = [true|false] 是否分布查询
  78. * @value true 启用分布查询,仅查询当前选中节点
  79. * @value false 关闭分布查询,一次查询出所有数据
  80. * @property {String|DBFieldString} self-field 分布查询当前字段名称
  81. * @property {String|DBFieldString} parent-field 分布查询父字段名称
  82. * @property {String|DBCollectionString} collection 表名
  83. * @property {String|DBFieldString} field 查询字段,多个字段用 `,` 分割
  84. * @property {String} orderby 排序字段及正序倒叙设置
  85. * @property {String|JQLString} where 查询条件
  86. * @event {Function} popupshow 弹出的选择窗口打开时触发此事件
  87. * @event {Function} popuphide 弹出的选择窗口关闭时触发此事件
  88. */
  89. export default {
  90. name: 'UniDataPicker',
  91. emits: ['popupopened', 'popupclosed', 'nodeclick', 'change', 'input', 'update:modelValue', 'inputclick'],
  92. mixins: [dataPicker],
  93. props: {
  94. popupTitle: {
  95. type: String,
  96. default: '请选择'
  97. },
  98. placeholder: {
  99. type: String,
  100. default: '请选择'
  101. },
  102. heightMobile: {
  103. type: String,
  104. default: ''
  105. },
  106. readonly: {
  107. type: Boolean,
  108. default: false
  109. },
  110. clearIcon: {
  111. type: Boolean,
  112. default: true
  113. },
  114. border: {
  115. type: Boolean,
  116. default: true
  117. },
  118. split: {
  119. type: String,
  120. default: '/'
  121. },
  122. ellipsis: {
  123. type: Boolean,
  124. default: true
  125. }
  126. },
  127. data() {
  128. return {
  129. isOpened: false
  130. }
  131. },
  132. computed: {
  133. isShowClearIcon() : boolean {
  134. if (this.readonly) {
  135. return false
  136. }
  137. if (this.clearIcon && this.selectedPaths.length > 0) {
  138. return true
  139. }
  140. return false
  141. }
  142. },
  143. created() {
  144. this.load()
  145. },
  146. methods: {
  147. clear() {
  148. },
  149. load() {
  150. if (this.isLocalData) {
  151. this.loadLocalData()
  152. } else if (this.isCloudDataList || this.isCloudDataTree) {
  153. this.loadCloudDataPath()
  154. }
  155. },
  156. show() {
  157. this.isOpened = true
  158. this.$emit('popupopened')
  159. if (!this.hasCloudTreeData) {
  160. this.loadData()
  161. }
  162. },
  163. hide() {
  164. this.isOpened = false
  165. this.$emit('popupclosed')
  166. },
  167. handleInput() {
  168. if (this.readonly) {
  169. this.$emit('inputclick')
  170. } else {
  171. this.show()
  172. }
  173. },
  174. handleClose() {
  175. this.hide()
  176. },
  177. onFinish() {
  178. this.selectedPaths = this.getChangeNodes()
  179. this.$emit('change', this.selectedPaths)
  180. this.hide()
  181. }
  182. }
  183. }
  184. </script>
  185. <style>
  186. @import url("../uni-data-pickerview/uni-data-pickerview.css");
  187. .uni-data-tree {
  188. position: relative;
  189. }
  190. .uni-data-tree-input {
  191. position: relative;
  192. }
  193. .selected-loading {
  194. display: flex;
  195. justify-content: center;
  196. position: absolute;
  197. left: 0;
  198. top: 0;
  199. right: 0;
  200. bottom: 0;
  201. }
  202. .error-text {
  203. flex: 1;
  204. font-size: 12px;
  205. color: #DD524D;
  206. }
  207. .input-value {
  208. flex-direction: row;
  209. align-items: center;
  210. flex-wrap: nowrap;
  211. padding: 5px 5px;
  212. padding-right: 5px;
  213. overflow: hidden;
  214. min-height: 28px;
  215. }
  216. .input-value-border {
  217. border: 1px solid #e5e5e5;
  218. border-radius: 5px;
  219. }
  220. .selected-path {
  221. flex: 1;
  222. flex-direction: row;
  223. overflow: hidden;
  224. }
  225. .load-more {
  226. width: 40px;
  227. }
  228. .selected-list {
  229. flex-direction: row;
  230. flex-wrap: nowrap;
  231. }
  232. .selected-item {
  233. flex-direction: row;
  234. flex-wrap: nowrap;
  235. }
  236. .text-color {
  237. font-size: 14px;
  238. color: #333;
  239. }
  240. .placeholder {
  241. color: grey;
  242. font-size: 14px;
  243. }
  244. .input-split-line {
  245. opacity: .5;
  246. margin-left: 1px;
  247. margin-right: 1px;
  248. }
  249. .arrow-area {
  250. position: relative;
  251. padding: 0 12px;
  252. margin-left: auto;
  253. justify-content: center;
  254. transform: rotate(-45deg);
  255. transform-origin: center;
  256. }
  257. .input-arrow {
  258. width: 8px;
  259. height: 8px;
  260. border-left: 2px solid #999;
  261. border-bottom: 2px solid #999;
  262. }
  263. .uni-data-tree-cover {
  264. position: fixed;
  265. left: 0;
  266. top: 0;
  267. right: 0;
  268. bottom: 0;
  269. background-color: rgba(0, 0, 0, .4);
  270. flex-direction: column;
  271. z-index: 100;
  272. }
  273. .uni-data-tree-dialog {
  274. position: fixed;
  275. left: 0;
  276. top: 20%;
  277. right: 0;
  278. bottom: 0;
  279. background-color: #FFFFFF;
  280. border-top-left-radius: 10px;
  281. border-top-right-radius: 10px;
  282. flex-direction: column;
  283. z-index: 102;
  284. overflow: hidden;
  285. }
  286. .dialog-caption {
  287. position: relative;
  288. flex-direction: row;
  289. }
  290. .dialog-title-view {
  291. flex: 1;
  292. }
  293. .dialog-title {
  294. align-self: center;
  295. padding: 0 10px;
  296. line-height: 44px;
  297. }
  298. .dialog-close {
  299. position: absolute;
  300. top: 0;
  301. right: 0;
  302. bottom: 0;
  303. flex-direction: row;
  304. align-items: center;
  305. padding: 0 15px;
  306. }
  307. .dialog-close-plus {
  308. width: 16px;
  309. height: 2px;
  310. background-color: #666;
  311. border-radius: 2px;
  312. transform: rotate(45deg);
  313. }
  314. .dialog-close-rotate {
  315. position: absolute;
  316. transform: rotate(-45deg);
  317. }
  318. .uni-data-pickerview {
  319. flex: 1;
  320. }
  321. .icon-clear {
  322. display: flex;
  323. align-items: center;
  324. }
  325. /* #ifdef H5 */
  326. @media all and (min-width: 768px) {
  327. .uni-data-tree-cover {
  328. background-color: transparent;
  329. }
  330. .uni-data-tree-dialog {
  331. position: absolute;
  332. top: 55px;
  333. height: auto;
  334. min-height: 400px;
  335. max-height: 50vh;
  336. background-color: #fff;
  337. border: 1px solid #EBEEF5;
  338. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  339. border-radius: 4px;
  340. overflow: unset;
  341. }
  342. .dialog-caption {
  343. display: none;
  344. }
  345. }
  346. /* #endif */
  347. </style>