cwg-detail-popup.vue 7.4 KB

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