cwg-detail-popup.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <cwg-popup v-model:visible="visible" type="center" :mask-click="false" :showFooters="true" :title="t('Btn.Detail')">
  3. <view class="popup-content">
  4. <view class="lines">
  5. <template v-if="items && items.length">
  6. <cwg-label-line-value v-for="(item, index) in items" :key="index" :label="item.label"
  7. :value="item.value" />
  8. </template>
  9. <template v-else-if="row && columns && columns.length">
  10. <cwg-label-line-value v-for="(item, index) in columns" :key="index" :label="item.label">
  11. <template #operation1>
  12. <slot :name="`cell-${item.prop}`" :row="row" :column="item" :index="index">
  13. <view v-if="item.type === 'action'" class="action-list">
  14. <view v-for="(actionItem, idx) in getVisibleActions(item.menuList, row)" :key="idx">
  15. <view class="action-btn"
  16. @click.stop="actionItem.btnClick && actionItem.btnClick(row)">
  17. {{ actionItem.label || actionItem.text || actionItem.name }}
  18. </view>
  19. </view>
  20. </view>
  21. <view class="value-text" v-else>{{ formatCellValue(row[item.prop], item, row) }}</view>
  22. </slot>
  23. </template>
  24. </cwg-label-line-value>
  25. </template>
  26. </view>
  27. </view>
  28. <template #footer>
  29. <button hover-class="" class="single-btn default" @click="visible = false" v-t="'Btn.Close'" />
  30. </template>
  31. </cwg-popup>
  32. </template>
  33. <script setup>
  34. import { ref, computed } from 'vue'
  35. import { useI18n } from 'vue-i18n'
  36. const { t } = useI18n()
  37. const props = defineProps({
  38. visible: { type: Boolean, default: false },
  39. title: { type: String, default: '详情' },
  40. // 旧方式
  41. items: { type: Array, default: () => [] },
  42. // 新方式
  43. row: { type: Object, default: null },
  44. columns: { type: Array, default: () => [] }
  45. })
  46. const emit = defineEmits(['update:visible', 'close'])
  47. // Watch for changes in visible prop and emit update event
  48. const visible = computed({
  49. get: () => props.visible,
  50. set: (value) => emit('update:visible', value)
  51. });
  52. // 过滤并获取允许显示的 action 按钮
  53. const getVisibleActions = (menuList, rowData) => {
  54. if (!menuList) return []
  55. return menuList.filter(item => {
  56. if (typeof item.show === 'function') {
  57. return item.show(rowData) !== false
  58. }
  59. return item.show !== false
  60. })
  61. }
  62. // 格式化标签文本 详情
  63. const formatTagText = (value, column) => {
  64. console.log()
  65. if (column.tagMap && column.tagMap[value]) {
  66. return column.tagMap[value]
  67. }
  68. return value || '-'
  69. }
  70. const formatCellValue = (value, column, row) => {
  71. // note , 详情展示备注
  72. if (column.type === 'note') {
  73. return row.note
  74. }
  75. if (column.formatter) {
  76. return column.formatter({ value, row })
  77. }
  78. if (column.type === 'date' && value) {
  79. return formatDate(value, column.dateFormat || 'YYYY-MM-DD HH:mm:ss')
  80. }
  81. if (column.type === 'tag' && value) {
  82. return formatTagText(value, column)
  83. }
  84. if (value === null || value === undefined) {
  85. return '-'
  86. }
  87. return value
  88. }
  89. const formatDate = (date, format) => {
  90. if (!date) return '-'
  91. const d = new Date(date)
  92. const year = d.getFullYear()
  93. const month = String(d.getMonth() + 1).padStart(2, '0')
  94. const day = String(d.getDate()).padStart(2, '0')
  95. const hour = String(d.getHours()).padStart(2, '0')
  96. const minute = String(d.getMinutes()).padStart(2, '0')
  97. const second = String(d.getSeconds()).padStart(2, '0')
  98. return format
  99. .replace('YYYY', year)
  100. .replace('MM', month)
  101. .replace('DD', day)
  102. .replace('HH', hour)
  103. .replace('mm', minute)
  104. .replace('ss', second)
  105. }
  106. </script>
  107. <style scoped lang="scss">
  108. @import "@/uni.scss";
  109. .action-list {
  110. display: flex;
  111. flex-direction: column;
  112. flex-wrap: wrap;
  113. gap: 6px 10px;
  114. align-items: flex-end;
  115. justify-content: center;
  116. }
  117. .action-btn {
  118. color: var(--color-primary);
  119. //text-decoration: underline;
  120. cursor: pointer;
  121. font-size: 14px;
  122. max-width: px2rpx(120);
  123. word-wrap: break-word;
  124. text-align: right;
  125. word-break: normal;
  126. //white-space: nowrap;
  127. }
  128. :deep(.uni-popup) {
  129. z-index: 101;
  130. }
  131. .dialog-header {
  132. display: flex;
  133. align-items: center;
  134. justify-content: space-between;
  135. padding: px2rpx(30) px2rpx(30) px2rpx(20);
  136. border-bottom: 1px solid var(--bs-border-color);
  137. .dialog-title {
  138. font-size: px2rpx(20);
  139. font-weight: 600;
  140. color: var(--bs-heading-color);
  141. }
  142. }
  143. .dialog-content {
  144. padding: px2rpx(20) px2rpx(30);
  145. max-height: 60vh;
  146. overflow-y: auto;
  147. // 自定义滚动条样式
  148. &::-webkit-scrollbar {
  149. width: px2rpx(6);
  150. }
  151. &::-webkit-scrollbar-thumb {
  152. background-color: #ddd;
  153. border-radius: px2rpx(3);
  154. }
  155. }
  156. .lines {
  157. display: flex;
  158. flex-direction: column;
  159. gap: px2rpx(10);
  160. }
  161. .actions {
  162. margin-top: px2rpx(16);
  163. display: flex;
  164. justify-content: center;
  165. }
  166. .actions button {
  167. min-width: px2rpx(160);
  168. height: px2rpx(40);
  169. border-radius: px2rpx(8);
  170. font-size: px2rpx(14);
  171. }
  172. .dialog-footer {
  173. padding: px2rpx(20) px2rpx(30) px2rpx(30);
  174. border-top: 1px solid #f0f0f0;
  175. // 双按钮模式
  176. &:not(:has(button:only-child)):has(button) {
  177. display: flex;
  178. justify-content: flex-end;
  179. gap: px2rpx(20);
  180. }
  181. // 单按钮模式
  182. &:has(button:only-child) {
  183. display: flex;
  184. justify-content: center;
  185. }
  186. .footer-line {
  187. height: 1px;
  188. background-color: #f0f0f0;
  189. margin: px2rpx(-20) 0 0;
  190. }
  191. button {
  192. min-width: px2rpx(120);
  193. height: px2rpx(40);
  194. border-radius: px2rpx(4);
  195. font-size: px2rpx(16);
  196. display: flex;
  197. align-items: center;
  198. justify-content: center;
  199. border: none;
  200. cursor: pointer;
  201. transition: all 0.3s ease;
  202. &:active {
  203. opacity: 0.8;
  204. transform: scale(0.98);
  205. }
  206. &:disabled {
  207. opacity: 0.5;
  208. cursor: not-allowed;
  209. }
  210. }
  211. .cancel-btn {
  212. background-color: #f5f5f5;
  213. color: var(--bs-heading-color);
  214. &:active {
  215. background-color: #e8e8e8;
  216. }
  217. }
  218. .confirm-btn {
  219. &.primary {
  220. background-color: #cf1322;
  221. color: var(--bs-emphasis-color);
  222. &:active {
  223. background-color: #0056b3;
  224. }
  225. }
  226. &.danger {
  227. background-color: #ff6b6b;
  228. color: var(--bs-emphasis-color);
  229. &:active {
  230. background-color: #ff5252;
  231. }
  232. }
  233. }
  234. .single-btn {
  235. min-width: px2rpx(200);
  236. &.primary {
  237. background-color: #cf1322;
  238. color: var(--bs-emphasis-color);
  239. }
  240. &.danger {
  241. background-color: #ff6b6b;
  242. color: var(--bs-emphasis-color);
  243. }
  244. &.default {
  245. background-color: #f5f5f5;
  246. color: var(--bs-heading-color);
  247. }
  248. }
  249. }
  250. .value-text {
  251. width: 100%;
  252. white-space: wrap;
  253. word-wrap: break-word;
  254. word-break: break-all;
  255. text-align: right;
  256. }
  257. </style>