tm-listitem.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <!-- 列表项目,类似单元格。 -->
  2. <template>
  3. <view class="tm-listitem ">
  4. <view
  5. @click="click"
  6. :style="[
  7. bgColor?{background:bgColor}:''
  8. ]"
  9. :class="[
  10. classStyle,
  11. `mx-${pz_themeCus.margin[0]} my-${pz_themeCus.margin[1]}`,
  12. disabled===true?(disabledColor + (black_tmeme?' bk ':'')) :(black_tmeme?'grey-darken-4 bk ':(bgColor?'':color)),
  13. dense?'nom':'',
  14. `shadow-${pz_themeCus.shadow}`,
  15. `round-${pz_themeCus.round}`,
  16. border?'border-a-1':''
  17. ]"
  18. >
  19. <view :class="['px-' + pz_themeCus.padding[0], 'py-' + pz_themeCus.padding[1]]">
  20. <view class="flex-between ">
  21. <view class="left flex-start ">
  22. <view class="left-tm-content mr-24 flex-center" v-if="showLeftIcon">
  23. <slot name="left" :icon="{ icon: leftIcon, color: color_tmeme, fontsize: leftIconSize }">
  24. <tm-icons v-if="!group" :color="color_tmeme" :name="leftIcon" :size="leftIconSize"></tm-icons>
  25. <tm-icons v-if="group" :color="color_tmeme" :name="!showContent ? 'icon-caret-right' : 'icon-sort-down'" :size="24"></tm-icons>
  26. </slot>
  27. </view>
  28. <view class="tm-content flex-col" style="width: 90%;">
  29. <view
  30. class="fulled flex-shrink"
  31. :class="[disabled===true?' text-grey-darken-1 ':(black_tmeme ? 'text-white' : `text-${titleColor}`)]"
  32. :style="{
  33. fontSize: fontSize + 'rpx'
  34. }"
  35. >
  36. <slot name="default" :title="title">{{ title }}</slot>
  37. </view>
  38. <view vif="label" class="fulled text-size-s text-weight-xs text-overflow-1 text-grey-lighten-1" :class="[label ? (dense ? 'pt-0' : 'pt-4') : '']">
  39. <slot name="label" :label="label">{{ label }}</slot>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="right text-grey-lighten-1 flex-end vertical-align-middle" :class="[black_tmeme ? 'bk' : '']">
  44. <view class="text-size-s pr-10 d-inline-block">
  45. <slot name="rightValue" :value="value">{{ value }}</slot>
  46. </view>
  47. <slot name="rightIcon" :icon="rightIcon">
  48. <tm-icons style="line-height: normal;" :color="rightIconColor" dense v-if="showRightIcon" :size="rightIconSize" :name="!showContent ? rightIcon : 'icon-angle-down'"></tm-icons>
  49. </slot>
  50. </view>
  51. </view>
  52. <view @click.stop="" class="group pt-24" v-if="showContent && group === true"><slot name="group" :show="showContent"></slot></view>
  53. </view>
  54. <view class="tm-listitem-border" :class="[pz_themeCus.borderBottom ? 'border-grey-lighten-4-b-1 ' : '',color, 'mx-' + pz_themeCus.padding[0], black_tmeme ? 'bk' : '']"></view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. /**
  60. * 列表
  61. * @description 配合tm-grouplist使用时,可以组合成手风琴模式。
  62. * @property {Boolean} black = [true|false] 默认:null,暗黑模式
  63. * @property {Number} round = [] 默认:4,单位upx, 外部圆角
  64. * @property {Array} margin = [] 默认:[0,0],单位upx,外间距。
  65. * @property {Array} padding = [] 默认:[32,32],单位upx,内间距。
  66. * @property {Number} shadow = [] 默认:6,单位upx,投影
  67. * @property {String} url = [] 默认:'',打开的链接。不空空时,将会打开链接,如果发生错误,会触发error事件。
  68. * @property {String} open-type = [navigate | navigateBack |reLaunch | redirect | switchTab] 默认:'navigate',打开的链接的方式。navigate | navigateBack |reLaunch | redirect | switchTab
  69. * @property {String} class-style = [] 默认:'',自定义类。
  70. * @property {Boolean} dense = [true|false] 默认:false,去除外间距。
  71. * @property {Boolean} border = [true|false] 默认:false,开启边线模式。
  72. * @property {Boolean} border-bottom = [true|false] 默认:false,是否显示下划线。
  73. * @property {String} bg-color = [] 默认:"",自定义背景色。
  74. * @property {String} disabled-color = [] 默认:"",禁用时的背景色
  75. * @property {String} color = [] 默认:"white",主题色
  76. * @property {String|Number} left-icon-size = [] 默认:"38",左边图标 大小 。
  77. * @property {String|Number} right-icon-size = [] 默认:"24",右边图标 大小 。
  78. * @property {String|Number} left-icon = [] 默认:"icon-gem",左边图标
  79. * @property {Boolean} show-left-icon = [true|false] 默认:false,是否显示左边图标。
  80. * @property {String} left-icon-color = [] 默认:"primary",左图标 主题色。
  81. * @property {String} right-icon = [] 默认:"icon-angle-right",左图标
  82. * @property {String} right-icon-color = [] 默认:"primary",右图标颜色。
  83. * @property {Boolean} show-right-icon = [] 默认:false, 是否显示右边图标。
  84. * @property {String} value = [] 默认:"", 右边文字。
  85. * @property {String} title = [] 默认:"",标题。
  86. * @property {String} title-color = [] 默认:"grey-darken-3",标题颜色。
  87. * @property {String} font-size = [] 默认:32,标题文字大小。
  88. * @property {String} label = [] 默认:"",下方文字说明。
  89. * @property {Boolean} group = [true|false] 默认:false,是否开启拓展功能,点击展开内容。slot:group的内容。
  90. * @property {Boolean} disabled = [true|false] 默认:false,是否禁用
  91. * @property {Function} click 点击组件时触发
  92. * @property {Function} error (当url不为空时,打开出错时发出)
  93. * @property {Function} change (当group为true时才会触发事件,显示和隐藏扩展内容。)
  94. * @example <tm-listitem title="而退役" value="9"></tm-listitem>
  95. */
  96. import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
  97. export default {
  98. components:{tmIcons},
  99. name: 'tm-listitem',
  100. props: {
  101. disabled: {
  102. type: Boolean,
  103. default: false
  104. },
  105. // 是否开启嵌套内容。
  106. group: {
  107. type: Boolean,
  108. default: false
  109. },
  110. // 打开的链接。不空空时,将会打开链接,如果发生错误,会触发error事件。
  111. url: {
  112. type: String,
  113. default: ''
  114. },
  115. // 打开的链接的方式。navigate | navigateBack |reLaunch | redirect | switchTab
  116. openType: {
  117. type: String,
  118. default: 'navigate'
  119. },
  120. black: {
  121. type: String | Boolean,
  122. default: null
  123. },
  124. //class.
  125. classStyle: {
  126. type: String,
  127. default: ''
  128. },
  129. // 去除外间距。
  130. dense: {
  131. type: Boolean,
  132. default: false
  133. },
  134. // false
  135. border: {
  136. type: String | Boolean,
  137. default: false
  138. },
  139. // 是否显示下划线
  140. borderBottom: {
  141. type: Boolean,
  142. default: false
  143. },
  144. // 自定义背景色。
  145. bgColor: {
  146. type: String,
  147. default: ''
  148. },
  149. // 主题色名称。
  150. color: {
  151. type: String,
  152. default: 'white'
  153. },
  154. // 主题色名称。
  155. disabledColor: {
  156. type: String,
  157. default: 'grey-lighten-3 text'
  158. },
  159. round: {
  160. type: String | Number,
  161. default: 3
  162. },
  163. leftIconSize: {
  164. type: String | Number,
  165. default: '32'
  166. },
  167. leftIcon: {
  168. type: String,
  169. default: 'icon-gem'
  170. },
  171. // 是否显示左边图标。
  172. showLeftIcon: {
  173. type: Boolean | String,
  174. default: false
  175. },
  176. leftIconColor: {
  177. type: String,
  178. default: 'primary'
  179. },
  180. rightIcon: {
  181. type: String,
  182. default: 'icon-angle-right'
  183. },
  184. rightIconSize: {
  185. type: String | Number,
  186. default: '24'
  187. },
  188. rightIconColor: {
  189. type: String,
  190. default: 'grey-lighten-1'
  191. },
  192. // 是否显示右边图标。
  193. showRightIcon: {
  194. type: Boolean | String,
  195. default: true
  196. },
  197. // 右边文字。
  198. value: {
  199. type: String,
  200. default: ''
  201. },
  202. // 标题。
  203. title: {
  204. type: String,
  205. default: ''
  206. },
  207. titleColor:{
  208. type:String,
  209. default:'grey-darken-3'
  210. },
  211. // 询部的文字说明
  212. label: {
  213. type: String,
  214. default: ''
  215. },
  216. shadow: {
  217. type: String | Number,
  218. default: 2
  219. },
  220. fontSize: {
  221. type: String | Number,
  222. default: '32'
  223. },
  224. // 单位upx
  225. margin: {
  226. type: Array,
  227. default: () => {
  228. return [32, 20];
  229. }
  230. },
  231. padding: {
  232. type: Array,
  233. default: () => {
  234. return [24, 20];
  235. }
  236. },
  237. flat:{
  238. type:String|Boolean,
  239. default:false,
  240. },
  241. // 跟随主题色的改变而改变。
  242. fllowTheme:{
  243. type:Boolean|String,
  244. default:true
  245. }
  246. },
  247. computed: {
  248. pz_themeCus: {
  249. get: function() {
  250. if(this.flat===true){
  251. return {
  252. margin: [0, 0],
  253. padding: [0, 0],
  254. shadow: 0,
  255. round: 0,
  256. borderBottom: false
  257. };
  258. }
  259. return this.pz_theme;
  260. },
  261. set: function(val) {
  262. val = val || {};
  263. this.pz_theme = {...val}
  264. }
  265. },
  266. black_tmeme:function(){
  267. if(this.black!==null) return this.black;
  268. return this.$tm.vx.state().tmVuetify.black;
  269. },
  270. color_tmeme:function(){
  271. if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
  272. return this.$tm.vx.state().tmVuetify.color;
  273. }
  274. return this.leftIconColor;
  275. }
  276. },
  277. data() {
  278. return {
  279. pz_theme: {
  280. margin: [0, 0],
  281. padding: [0, 0],
  282. shadow: 0,
  283. round: 0,
  284. borderBottom: false
  285. },
  286. showContent: false
  287. };
  288. },
  289. created() {
  290. this.pz_themeCus = {
  291. margin: this.margin,
  292. padding: this.padding,
  293. shadow: this.shadow,
  294. round: this.round,
  295. borderBottom: this.borderBottom
  296. };
  297. },
  298. mounted() {
  299. },
  300. methods: {
  301. click(e) {
  302. if(this.disabled===true) return;
  303. let t = this;
  304. if (this.group === true && typeof this.group === 'boolean') {
  305. this.showContent = !this.showContent;
  306. if (!this.$tm.getParentAls('tm-listitem', this.$parent)) {
  307. let preat = this.$tm.getParentAls('tm-grouplist', this.$parent);
  308. if(preat){
  309. preat.change(t._uid);
  310. }
  311. }
  312. this.$emit('change', this.showContent);
  313. return;
  314. }
  315. if (!this.url) {
  316. this.$emit('click', e);
  317. return ;
  318. }
  319. if (this.openType === 'switchTab') {
  320. uni.switchTab({
  321. url: this.url,
  322. fail: er => {
  323. t.$emit('error', er);
  324. }
  325. });
  326. }else{
  327. uni.navigateTo({
  328. url:this.url
  329. })
  330. }
  331. },
  332. setConfig(val){
  333. this.$nextTick(function(){
  334. this.pz_themeCus = {...this.pz_themeCus,...val};
  335. })
  336. }
  337. }
  338. };
  339. </script>
  340. <style lang="scss" scoped>
  341. .tm-listitem {
  342. position: relative;
  343. .tm-listitem-border {
  344. }
  345. .nom{
  346. margin: 0 !important;
  347. padding: 0 !important;
  348. }
  349. }
  350. .left {
  351. max-width: 400upx;
  352. width: 400upx;
  353. .left-tm-content {
  354. max-width: 100upx;
  355. line-height: 0;
  356. }
  357. .tm-content {
  358. max-width: 290upx;
  359. justify-content: center;
  360. align-content: center;
  361. display: flex;
  362. }
  363. }
  364. .right{
  365. // #ifdef MP
  366. line-height: 0;
  367. // #endif
  368. }
  369. .group {
  370. transition: all 0.6s;
  371. }
  372. </style>