index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="h-100 position-relative">
  3. <div class="dashboard-card-wrap" :style="wrapStyle">
  4. <div class="dashboard-card-header" style="margin-bottom:0">
  5. <div class="dashboard-card-header-left">
  6. <span :style="headerStyle">{{ form.fd.name || $t('dashboard.title_bar') }}</span>
  7. <a-icon class="ml-2" type="loading" v-if="loading" /></div>
  8. <div class="dashboard-card-header-right">
  9. <slot name="actions" :handle-edit="handleEdit" />
  10. </div>
  11. </div>
  12. <div v-if="desc" class="dashboard-card-body flex-column justify-content-center" :style="descStyle">
  13. {{ desc }}
  14. </div>
  15. </div>
  16. <base-drawer :visible.sync="visible" :title="$t('dashboard.text_5')" @ok="handleSubmit" @cancel="handleCancel">
  17. <a-form
  18. :form="form.fc"
  19. v-bind="formItemLayout">
  20. <a-form-item :label="$t('dashboard.text_6')">
  21. <a-input v-decorator="decorators.name" />
  22. </a-form-item>
  23. <a-form-item :label="$t('dashboard.explain')">
  24. <a-input v-decorator="decorators.desc" />
  25. </a-form-item>
  26. <a-form-item :label="$t('dashboard.background')">
  27. <div class="d-flex flex-wrap" style="line-height: 30px">
  28. <a-tooltip class="color-item" v-for="(item, index) in colorList" :key="index">
  29. <template slot="title">
  30. {{ item.key }}
  31. </template>
  32. <a-tag :color="item.color" @click="changeColor(item.color)" :style="item.color === '#FFFFFF' ? {border:'solid #ccc 1px'} : {}">
  33. <a-icon type="check" v-if="item.color === form.fd.color" :style="item.color === '#FFFFFF' ? {color:'#333'} : {}" />
  34. </a-tag>
  35. </a-tooltip>
  36. </div>
  37. </a-form-item>
  38. </a-form>
  39. </base-drawer>
  40. </div>
  41. </template>
  42. <script>
  43. import { mapGetters } from 'vuex'
  44. import BaseDrawer from '@Dashboard/components/BaseDrawer'
  45. import { colorList } from '@/utils/theme/utils'
  46. export default {
  47. name: 'Title',
  48. components: {
  49. BaseDrawer,
  50. },
  51. props: {
  52. options: {
  53. type: Object,
  54. required: true,
  55. },
  56. params: Object,
  57. edit: Boolean,
  58. },
  59. data () {
  60. const initialNameValue = (this.params && this.params.name) || this.$t('dashboard.title_bar')
  61. const initialDesc = (this.params && this.params.desc) || ''
  62. const initialColor = (this.params && this.params.color) || '#FFFFFF'
  63. return {
  64. data: [],
  65. visible: false,
  66. loading: false,
  67. form: {
  68. fc: this.$form.createForm(this),
  69. fd: {
  70. name: initialNameValue,
  71. desc: initialDesc,
  72. color: initialColor,
  73. },
  74. },
  75. decorators: {
  76. name: [
  77. 'name',
  78. {
  79. initialValue: initialNameValue,
  80. rules: [
  81. { required: true, message: this.$t('dashboard.text_8') },
  82. ],
  83. },
  84. ],
  85. desc: [
  86. 'desc',
  87. {
  88. initialValue: initialDesc,
  89. },
  90. ],
  91. color: [
  92. 'color',
  93. {
  94. initialValue: initialColor,
  95. },
  96. ],
  97. },
  98. formItemLayout: {
  99. wrapperCol: {
  100. span: 18,
  101. },
  102. labelCol: {
  103. span: 6,
  104. },
  105. },
  106. colorList: [
  107. ...colorList,
  108. {
  109. key: this.$t('dashboard.color_white'),
  110. color: '#FFFFFF',
  111. },
  112. ],
  113. }
  114. },
  115. computed: {
  116. ...mapGetters(['scope', 'userInfo']),
  117. desc () {
  118. return this.form.fd.desc
  119. },
  120. bgColor () {
  121. return (this.params && this.params.color) || '#FFFFFF'
  122. },
  123. headerStyle () {
  124. const ret = {
  125. fontSize: '1.3em',
  126. fontWeight: 'bold',
  127. }
  128. if (!this.desc) {
  129. ret.height = '50px'
  130. ret.lineHeight = '50px'
  131. }
  132. if (this.params && this.params.color && this.params.color !== '#FFFFFF') {
  133. ret.color = '#fff'
  134. }
  135. return ret
  136. },
  137. wrapStyle () {
  138. const ret = {
  139. padding: '12px 15px',
  140. }
  141. if (this.params && this.params.color && this.params.color !== '#FFFFFF') {
  142. ret.background = this.params.color
  143. }
  144. return ret
  145. },
  146. descStyle () {
  147. if (this.params && this.params.color && this.params.color !== '#FFFFFF') {
  148. return { color: '#fff' }
  149. }
  150. return {}
  151. },
  152. },
  153. watch: {
  154. 'form.fd' (val) {
  155. for (const key in this.decorators) {
  156. let config = this.decorators[key][1] || {}
  157. config = {
  158. ...config,
  159. initialValue: val[key],
  160. }
  161. this.decorators[key][1] = config
  162. }
  163. },
  164. },
  165. destroyed () {
  166. this.manager = null
  167. },
  168. created () {
  169. this.$emit('update', this.options.i, {
  170. ...this.form.fd,
  171. })
  172. },
  173. methods: {
  174. changeColor (color) {
  175. this.form.fd.color = color
  176. },
  177. refresh () {
  178. return function () {}
  179. },
  180. handleEdit () {
  181. this.visible = true
  182. },
  183. async handleSubmit () {
  184. try {
  185. const values = await this.form.fc.validateFields()
  186. this.form.fd = { ...values, color: this.form.fd.color }
  187. this.$emit('update', this.options.i, { ...values, color: this.form.fd.color })
  188. this.visible = false
  189. } catch (error) {
  190. throw error
  191. }
  192. },
  193. handleCancel () {
  194. this.form.fd.color = (this.params && this.params.color) || '#fff'
  195. },
  196. },
  197. }
  198. </script>
  199. <style scoped lang="less">
  200. .color-item {
  201. width: 20px;
  202. height: 20px;
  203. border-radius: 2px;
  204. cursor: pointer;
  205. margin-right: 8px;
  206. padding-left: 0px;
  207. padding-right: 0px;
  208. text-align: center;
  209. color: #fff;
  210. font-weight: 700;
  211. i {
  212. font-size: 14px;
  213. }
  214. }
  215. </style>