index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <section
  3. class="project-cell cell-clickable"
  4. v-on="$listeners"
  5. :class="{
  6. visited: visited,
  7. 'colorful-cell': isNotDefault,
  8. 'jy-hairline--bottom': line
  9. }"
  10. >
  11. <div class="title-group">
  12. <div
  13. class="title"
  14. :class="{ 'van-multi-ellipsis--l5': ellipsis }"
  15. @click="$emit('click-title')"
  16. >
  17. <span v-if="isDefault && isFile" class="title-file">
  18. <slot>{{ fileText }}</slot>
  19. </span>
  20. <span v-html="getTitle"></span>
  21. <span v-if="filetext_search" style="padding-left: 8px"
  22. >(<span style="color: #2abed1">{{ setKeyLength }}</span
  23. >在附件中)</span
  24. >
  25. </div>
  26. <div class="title-icon" v-if="isDefault">
  27. <slot name="icon"></slot>
  28. </div>
  29. </div>
  30. <div class="info-group">
  31. <template v-if="isDefault">
  32. <div class="tag-group">
  33. <span
  34. class="tag-item"
  35. :class="item.className"
  36. v-for="(item, index) in tagList"
  37. :key="index"
  38. @click="$emit('click-tag', item)"
  39. >
  40. <slot name="tag-item">{{ item.name }}</slot>
  41. </span>
  42. </div>
  43. <span class="tag-item--time">{{ getTime }}</span>
  44. </template>
  45. <template v-else>
  46. <div class="tag-group">
  47. <slot name="left-top-badge">
  48. <div class="tag-item red" v-if="leftTopBadgeText">
  49. {{ leftTopBadgeText }}
  50. </div>
  51. </slot>
  52. <span
  53. class="tag-item"
  54. :class="item.className"
  55. v-for="(item, index) in tagList"
  56. :key="index"
  57. @click="$emit('click-tag', item)"
  58. >
  59. <slot name="tag-item">{{ item.name }}</slot>
  60. </span>
  61. <span v-if="isFile && fileText" class="tag-item title-file main">
  62. <slot>{{ fileText.replace(/[\[\]]/g, '') }}</slot>
  63. </span>
  64. <span
  65. v-if="pushSourceTag.text"
  66. class="tag-item push-source-tag"
  67. :class="pushSourceTag.className"
  68. >{{ pushSourceTag.text }}</span
  69. >
  70. </div>
  71. </template>
  72. </div>
  73. <div
  74. class="detail"
  75. v-if="detail && getDetail"
  76. :class="{ 'van-ellipsis': ellipsis }"
  77. v-html="getDetail"
  78. ></div>
  79. <div
  80. class="more-detail detail-list"
  81. v-show="isDetailed && detailList.length"
  82. >
  83. <div
  84. class="detail-item"
  85. v-for="(item, index) in detailList"
  86. :class="item.className"
  87. v-show="item.text"
  88. :key="index"
  89. >
  90. <!-- 使用此处插槽必须保证 item.text 有值 -->
  91. <slot
  92. v-if="item.detailItemSlot"
  93. :name="item.detailItemSlot"
  94. :item="item"
  95. ></slot>
  96. <template v-else>
  97. <span class="detail-label">{{ item.label }}</span>
  98. <span class="detail-splitter">{{ item.splitter }}</span>
  99. <span
  100. class="detail-text"
  101. :class="{ 'highlight-text': item.highlightText }"
  102. key="detail-text"
  103. >
  104. <template v-if="item.detailTextSlot">
  105. <slot :name="item.detailTextSlot" :item="item"></slot>
  106. </template>
  107. <template v-else>{{ item.text }}</template>
  108. </span>
  109. </template>
  110. </div>
  111. </div>
  112. <div
  113. class="footer-container"
  114. :class="{ 'van-hairline--top': isNotDefault }"
  115. >
  116. <template v-if="isDefault">
  117. <slot name="left-top-badge">
  118. <div class="badge left-top red" v-if="leftTopBadgeText">
  119. {{ leftTopBadgeText }}
  120. </div>
  121. </slot>
  122. <div class="footer-container">
  123. <div class="tag-group" v-if="pushSourceTag.text">
  124. <span
  125. class="tag-item push-source-tag"
  126. :class="pushSourceTag.className"
  127. >{{ pushSourceTag.text }}</span
  128. >
  129. </div>
  130. </div>
  131. </template>
  132. <template v-else>
  133. <span class="tag-item--time">{{ getTime }}</span>
  134. <div class="title-icon">
  135. <slot name="icon"></slot>
  136. </div>
  137. </template>
  138. </div>
  139. </section>
  140. </template>
  141. <script>
  142. import { dateFormatter, dateFromNow, replaceKeyword } from '@/utils'
  143. import { AppIcon } from '@/ui'
  144. export default {
  145. name: 'ProjectCell',
  146. components: {
  147. [AppIcon.name]: AppIcon
  148. },
  149. props: {
  150. /**
  151. * cell的状态
  152. * ''为默认值,表示最初的样式
  153. * simplify 表示精简列表
  154. * detailed 表示详细列表
  155. */
  156. cardType: {
  157. type: String,
  158. default: '',
  159. validator(value) {
  160. return ['', 'simplify', 'detailed'].includes(value)
  161. }
  162. },
  163. title: {
  164. type: String,
  165. default: ''
  166. },
  167. ellipsis: {
  168. type: Boolean,
  169. default: true
  170. },
  171. line: {
  172. type: Boolean,
  173. default: true
  174. },
  175. detail: {
  176. type: String,
  177. default: ''
  178. },
  179. filetext_search: {
  180. type: Boolean,
  181. default: false
  182. },
  183. visited: {
  184. type: Boolean,
  185. default: false
  186. },
  187. keys: {
  188. type: Array,
  189. default() {
  190. return []
  191. }
  192. },
  193. /**
  194. * ['string', 'string']
  195. * 或者
  196. * [{ name: 'xxx', className: 'grey' }]
  197. */
  198. tags: {
  199. type: Array,
  200. default() {
  201. return []
  202. }
  203. },
  204. /**
  205. * [
  206. * {
  207. * label: 'xxx',
  208. * highlightText: true,
  209. * splitter: ':',
  210. * className: ':',
  211. * text: '123123'
  212. * }
  213. * ]
  214. */
  215. detailList: {
  216. type: Array,
  217. default() {
  218. return []
  219. }
  220. },
  221. time: {
  222. type: [Number, String],
  223. default: ''
  224. },
  225. timeFmt: {
  226. type: String,
  227. default: ''
  228. },
  229. /**
  230. * 左上角角标
  231. */
  232. leftTopBadgeText: {
  233. type: String,
  234. default: ''
  235. },
  236. isFile: {
  237. type: Boolean,
  238. default: false
  239. },
  240. // 1个人订阅 2企业自动分发 3企业手动分发 0或者空则不显示
  241. pushSource: {
  242. type: Number,
  243. default: 0
  244. },
  245. fileText: {
  246. type: String,
  247. default: '[有附件]'
  248. }
  249. },
  250. data() {
  251. return {
  252. tagSourceMap: {
  253. 1: {
  254. className: 'main',
  255. text: '个人订阅'
  256. },
  257. 2: {
  258. className: 'orange',
  259. text: '企业自动分发'
  260. },
  261. 3: {
  262. className: 'orange',
  263. text: '企业手动分发'
  264. }
  265. }
  266. }
  267. },
  268. computed: {
  269. isDefault() {
  270. return this.cardType === ''
  271. },
  272. isSimplify() {
  273. return this.cardType === 'simplify'
  274. },
  275. isDetailed() {
  276. return this.cardType === 'detailed'
  277. },
  278. isNotDefault() {
  279. return this.isSimplify || this.isDetailed
  280. },
  281. tagList() {
  282. return this.tags.map((tag) => {
  283. if (!tag || typeof tag === 'string') {
  284. return {
  285. name: tag,
  286. className: 'grey'
  287. }
  288. } else {
  289. return tag
  290. }
  291. })
  292. },
  293. pushSourceTag() {
  294. return this.tagSourceMap[this.pushSource] || {}
  295. },
  296. getTitle() {
  297. return replaceKeyword(this.title, this.keys)
  298. },
  299. getDetail() {
  300. // 有匹配词且匹配上才显示正文
  301. if (this.setDetailText) {
  302. return replaceKeyword(this.setDetailText, this.keys)
  303. } else {
  304. return ''
  305. }
  306. },
  307. // 正文开头和高亮词之间,最多保留10个字符
  308. setDetailText() {
  309. // 正则匹配标签置为空
  310. const detail = this.detail.replace(/<[^>]+>/g, '')
  311. let postion = detail.indexOf(this.keys[0])
  312. if (postion !== -1) {
  313. if (postion - 10 > 0) {
  314. return detail.substring(postion - 10)
  315. } else {
  316. return ''
  317. }
  318. } else {
  319. return ''
  320. }
  321. },
  322. getTime() {
  323. if (this.timeFmt) {
  324. return dateFormatter(this.time, this.timeFmt)
  325. } else {
  326. return dateFromNow(this.time)
  327. }
  328. },
  329. setKeyLength() {
  330. const key = this.keys[0]
  331. if (key) {
  332. if (key.length > 3) {
  333. return key.substring(0, 3) + '...'
  334. } else {
  335. return key
  336. }
  337. } else {
  338. return ''
  339. }
  340. }
  341. },
  342. methods: {}
  343. }
  344. </script>
  345. <style lang="scss" scoped>
  346. .bold {
  347. font-weight: 500;
  348. }
  349. .project-cell {
  350. position: relative;
  351. padding: 12px 16px;
  352. font-weight: 400;
  353. font-size: 16px;
  354. line-height: 24px;
  355. color: #171826;
  356. background-color: $white;
  357. .badge {
  358. position: absolute;
  359. display: flex;
  360. justify-content: center;
  361. align-items: center;
  362. padding: 0 8px;
  363. border-radius: 0px 0px 12px 0px;
  364. font-size: 12px;
  365. line-height: 19px;
  366. &.left-top {
  367. left: 0;
  368. top: 0;
  369. }
  370. &.red {
  371. color: $red;
  372. background-color: $color_red_background;
  373. }
  374. }
  375. .title-group {
  376. margin: 4px 0 12px 0;
  377. display: flex;
  378. flex-direction: row;
  379. align-items: flex-start;
  380. .title {
  381. flex: 1;
  382. }
  383. .title-file {
  384. margin-right: 4px;
  385. color: $color_main;
  386. font-size: 16px;
  387. }
  388. }
  389. .title-icon {
  390. display: flex;
  391. align-items: center;
  392. flex-shrink: 0;
  393. margin-left: 18px;
  394. font-size: 14px;
  395. line-height: 20px;
  396. color: $gray_7;
  397. > div,
  398. span {
  399. display: flex;
  400. align-items: center;
  401. }
  402. }
  403. .tag-group {
  404. display: flex;
  405. flex-direction: row;
  406. align-items: center;
  407. flex-wrap: wrap;
  408. }
  409. .tag-item {
  410. margin: 2px;
  411. display: inline-block;
  412. box-sizing: border-box;
  413. border-radius: 4px;
  414. padding: 1px 8px;
  415. white-space: nowrap;
  416. border: 0.5px solid transparent;
  417. &.grey {
  418. color: #5f5e64;
  419. background: #f7f9fa;
  420. border-color: rgba(0, 0, 0, 0.05);
  421. }
  422. &.main {
  423. color: $main;
  424. background: $color_main_background;
  425. border-color: $color_main_background;
  426. }
  427. &.orange {
  428. color: $gold_deep;
  429. background: $color_gold_deep_background;
  430. border-color: $color_gold_deep_background;
  431. }
  432. &.red {
  433. color: $red;
  434. background-color: $color_red_background;
  435. }
  436. &--time {
  437. color: #9b9ca3;
  438. white-space: nowrap;
  439. }
  440. }
  441. .info-group {
  442. display: flex;
  443. flex-direction: row;
  444. align-items: center;
  445. justify-content: space-between;
  446. font-weight: 400;
  447. font-size: 12px;
  448. line-height: 18px;
  449. }
  450. .detail {
  451. font-size: 13px;
  452. line-height: 20px;
  453. color: #5f5e64;
  454. margin-top: 12px;
  455. margin-bottom: 4px;
  456. }
  457. &.visited,
  458. &.hover {
  459. .title,
  460. .detail {
  461. color: #c0c4cc;
  462. }
  463. .tag-item {
  464. opacity: 0.6;
  465. }
  466. }
  467. .footer-container {
  468. .tag-group {
  469. margin-top: 6px;
  470. font-size: 12px;
  471. line-height: 18px;
  472. }
  473. }
  474. .more-detail {
  475. margin-bottom: 12px;
  476. }
  477. .detail-item {
  478. font-size: 13px;
  479. line-height: 20px;
  480. color: $gray_9;
  481. }
  482. .detail-label {
  483. color: $gray_7;
  484. }
  485. &.colorful-cell {
  486. display: flex;
  487. flex-direction: column;
  488. .title-group {
  489. margin: 4px 0;
  490. }
  491. .info-group {
  492. order: 4;
  493. margin-bottom: 12px;
  494. align-items: flex-start;
  495. flex-direction: column;
  496. }
  497. .detail {
  498. order: 2;
  499. margin-top: 0;
  500. margin-bottom: 4px;
  501. }
  502. .more-detail {
  503. order: 6;
  504. }
  505. .tag-item {
  506. &--time {
  507. font-size: 12px;
  508. }
  509. }
  510. .footer-container {
  511. order: 8;
  512. display: flex;
  513. align-items: center;
  514. justify-content: space-between;
  515. padding-top: 10px;
  516. }
  517. }
  518. }
  519. </style>