editColumn.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div v-loading="loading" class="edit_table_column">
  3. <el-input v-show="edit" v-model="scope.row[prop]" type="textarea" :rows="6" />
  4. <div v-show="!edit" class="content" :title="scope.row[prop]" v-html="scope.row[prop]" />
  5. <el-button v-show="!edit" size="mini" icon="el-icon-edit" @click="editSeoTableColumnEvent(scope,'edit')" />
  6. <el-button v-show="edit" type="primary" size="mini" icon="el-icon-check" @click="editSeoTableColumnEvent(scope,'save')" />
  7. <div v-if="prop === 'seo_title' && scope.row[prop]" class="limit_tips">
  8. (<span v-if="word>66" style="color: red">{{ word }}</span><span v-else>{{ word }}</span>/66)
  9. </div>
  10. <div v-else-if="prop === 'seo_describe' && scope.row[prop]" class="limit_tips">
  11. (<span v-if="word>250" style="color: red">{{ word }}</span><span v-else>{{ word }}</span>/250)
  12. </div>
  13. <div v-else class="limit_tips" />
  14. </div>
  15. </template>
  16. <script>
  17. import { updateSEO } from '@/api/system'
  18. import Vue from 'vue'
  19. export default Vue.extend({
  20. name: 'EditColumn',
  21. props: {
  22. prop: {
  23. default: '',
  24. type: String
  25. },
  26. scope: {
  27. default: null,
  28. type: Object
  29. }
  30. },
  31. data() {
  32. return {
  33. loading: false,
  34. edit: false
  35. }
  36. },
  37. computed: {
  38. word() {
  39. return this.scope.row[this.prop].replace(/[^\x00-\xff]/g, '01').length
  40. }
  41. },
  42. methods: {
  43. editSeoTableColumnEvent(scope, type) {
  44. if (type === 'edit') {
  45. this.edit = true
  46. } else {
  47. this.loading = true
  48. this.$emit('loadingEvent', true)
  49. updateSEO({
  50. id: scope.row.seo_id ? scope.row.seo_id : scope.row.id,
  51. seo_title: scope.row.seo_title,
  52. seo_keyword: scope.row.seo_keyword,
  53. seo_describe: scope.row.seo_describe
  54. }).then(() => {
  55. this.edit = false
  56. this.loading = false
  57. this.$emit('save', scope)
  58. this.$emit('loadingEvent', false)
  59. })
  60. }
  61. }
  62. }
  63. })
  64. </script>
  65. <style lang="scss" scoped>
  66. .edit_table_column {
  67. position: relative;
  68. .limit_tips {
  69. height: 32px;
  70. width: 100%;
  71. display: block;
  72. }
  73. .content {
  74. display: -webkit-box;
  75. overflow: hidden;
  76. text-overflow: ellipsis;
  77. -webkit-box-orient: vertical;
  78. -webkit-line-clamp: 4;
  79. word-break: break-word;
  80. }
  81. .el-button {
  82. opacity: 0;
  83. z-index: 2;
  84. position: absolute;
  85. right: 0;
  86. bottom: 0;
  87. }
  88. &:hover {
  89. .el-button {
  90. opacity: 1;
  91. }
  92. }
  93. }
  94. </style>