sa-info.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <!-- 自定义slot -->
  3. <div class="c-item" :class="{br: br}" v-if="$slots.default">
  4. <label class="c-label" v-if="name && name.length > 0">{{name}}:</label>
  5. <span v-else-if="name === undefined"></span>
  6. <label class="c-label" v-else></label>
  7. <span v-else></span>
  8. <slot></slot>
  9. </div>
  10. <!-- 普通信息 -->
  11. <div class="c-item" :class="{br: br}" v-else-if="type == 'text'">
  12. <label class="c-label">{{name}}:</label>
  13. <span>{{value}}</span>
  14. <span v-if="sa.isNull(value)">无</span>
  15. </div>
  16. <!-- num -->
  17. <div class="c-item" :class="{br: br}" v-else-if="type == 'num'">
  18. <label class="c-label">{{name}}:</label>
  19. <span class="tc-num">{{value}}</span>
  20. <span v-if="sa.isNull(value)">无</span>
  21. </div>
  22. <!-- textarea -->
  23. <div class="c-item" :class="{br: br}" v-else-if="type == 'textarea'">
  24. <label class="c-label">{{name}}:</label>
  25. <span class="c-item-mline" v-if="sa.isNull(value) == false">{{value}}</span>
  26. <span v-if="sa.isNull(value)">无</span>
  27. </div>
  28. <!-- text-list -->
  29. <div class="c-item" :class="{br: br}" v-else-if="type == 'text-list'">
  30. <label class="c-label">{{name}}:</label>
  31. <div class="c-item-mline" v-if="value_arr.length > 0">
  32. <div v-for="item in value_arr">
  33. <p class="s-text-list-p">{{item}}</p>
  34. </div>
  35. </div>
  36. <span v-else>无</span>
  37. </div>
  38. <!-- img -->
  39. <div class="c-item" :class="{br: br}" v-else-if="type == 'img'">
  40. <label class="c-label">{{name}}:</label>
  41. <img :src="value" class="info-img" @click="sa.showImage(value, '400px', '400px')" v-if="value">
  42. <span v-else>无</span>
  43. </div>
  44. <!-- audio、video、file -->
  45. <div class="c-item" :class="{br: br}" v-else-if="type == 'audio' || type == 'video' || type == 'file'">
  46. <label class="c-label">{{name}}:</label>
  47. <el-link type="info" :href="value" target="_blank" v-if="!sa.isNull(value)">{{value}}</el-link>
  48. <span v-else>无</span>
  49. </div>
  50. <!-- img-list -形如:url1,url2,url3 -->
  51. <div class="c-item" :class="{br: br}" v-else-if="type == 'img-list'">
  52. <label class="c-label">{{name}}:</label>
  53. <div class="c-item-mline image-box image-box-info" v-if="value_arr.length > 0">
  54. <div class="image-box-2" v-for="image in value_arr">
  55. <img :src="image" @click="sa.showImage(image, '500px', '400px')" />
  56. </div>
  57. </div>
  58. <span v-else>无</span>
  59. </div>
  60. <!-- audio-list、video-list、file-list、img-video-list -->
  61. <div class="c-item" :class="{br: br}" v-else-if="type == 'audio-list' || type == 'video-list' || type == 'file-list' || type == 'img-video-list'">
  62. <label class="c-label">{{name}}:</label>
  63. <div class="c-item-mline" v-if="value_arr.length > 0">
  64. <div v-for="item in value_arr">
  65. <el-link type="info" :href="item" target="_blank">{{item}}</el-link>
  66. </div>
  67. </div>
  68. <span v-else>无</span>
  69. </div>
  70. <!-- 钱 money (单位 元) -->
  71. <div class="c-item" :class="{br: br}" v-else-if="type == 'money'">
  72. <label class="c-label">{{name}}:</label>
  73. <b class="c-price">¥{{value}}</b>
  74. </div>
  75. <!-- 钱 price-f (单位 分) -->
  76. <div class="c-item" :class="{br: br}" v-else-if="type == 'money-f'">
  77. <label class="c-label">{{name}}:</label>
  78. <b class="c-price">¥{{value / 100}}</b>
  79. </div>
  80. <!-- 富文本 richtext f -->
  81. <div class="c-item" :class="{br: br}" v-else-if="type == 'richtext' || type == 'f'">
  82. <label class="c-label">{{name}}:</label>
  83. <div class="editor-box content-box-info c-item-mline">
  84. <div v-html="value"></div>
  85. </div>
  86. </div>
  87. <!-- 显示枚举 j、num -->
  88. <div class="c-item" :class="{br: br}" v-else-if="type == 'enum' || type == 'j' || type == 'switch'">
  89. <label class="c-label">{{name}}:</label>
  90. <span v-for="j in jvList" :key="j.key">
  91. <b :style="{color: j.color || '#303236'}" v-if="value == j.key">{{j.value}}</b>
  92. </span>
  93. </div>
  94. <!-- link -->
  95. <div class="c-item" :class="{br: br}" v-else-if="type == 'link'">
  96. <label class="c-label">{{name}}:</label>
  97. <!-- <span class="c-item-mline">{{value}}</span> -->
  98. <el-link type="primary" :href="value" target="_blank" v-if="!sa.isNull(value)">{{value}}</el-link>
  99. <span v-else>无</span>
  100. </div>
  101. <!-- 日期 -->
  102. <div class="c-item" :class="{br: br}" v-else-if="type == 'date'">
  103. <label class="c-label">{{name}}:</label>
  104. <span class="tc-date">{{sa.forDate(value, 1)}}</span>
  105. <span v-if="sa.isNull(value)">无</span>
  106. </div>
  107. <!-- 日期时间 -->
  108. <div class="c-item" :class="{br: br}" v-else-if="type == 'datetime'">
  109. <label class="c-label">{{name}}:</label>
  110. <span class="tc-date">{{sa.forDate(value, 2)}}</span>
  111. <span v-if="sa.isNull(value)">无</span>
  112. </div>
  113. <!-- 时间 -->
  114. <div class="c-item" :class="{br: br}" v-else-if="type == 'time'">
  115. <label class="c-label">{{name}}:</label>
  116. <span class="tc-date">{{value}}</span>
  117. <span v-if="sa.isNull(value)">无</span>
  118. </div>
  119. <!-- 评分组件 -->
  120. <div class="c-item" :class="{br: br}" v-else-if="type == 'rate'">
  121. <label class="c-label">{{name}}:</label>
  122. <div style="display: inline-block;">
  123. <el-rate :value="value <= 5 ? value : 5" show-text disabled></el-rate>
  124. <span v-if="sa.isNull(value)">无</span>
  125. </div>
  126. </div>
  127. </template>
  128. <script>
  129. module.exports = {
  130. // props: ['name', 'value'],
  131. props: {
  132. // text、num、
  133. type: {
  134. default: 'text'
  135. },
  136. // label提示文字
  137. name: {
  138. type: String
  139. },
  140. // 绑定的值
  141. value: {},
  142. // 提示文字
  143. placeholder: {},
  144. // 是否禁用
  145. disabled: {},
  146. // 是否换行
  147. br: {
  148. type: Boolean,
  149. default: false
  150. },
  151. // type=menu时,值列表 -- 形如:{1: '正常[green]', 2: '禁用[red]'}
  152. jv: {default: ''},
  153. // type=menu时,具体的枚举类型 -- 1=单选框,2=单选文字,3=单选按钮,4=单选下拉框
  154. jtype: {default: 1},
  155. // 级联选择的数据列表
  156. options: {},
  157. // 快捷按钮显示列表,形如:add,get,delete,export,reset
  158. show: {},
  159. // 分页信息
  160. curr: {}, size: {}, total: {}, sizes: {},
  161. // 空值时显示的文字
  162. not: {default: '无'}
  163. },
  164. data() {
  165. return {
  166. // 日期范围时的值
  167. dateRangeValue: [],
  168. // 快捷按钮显示按钮列表
  169. showBtns: [],
  170. // type=menu时,解析的值列表 -- 形如:[{key: 1, value: '正常', color: 'green'}]
  171. jvList: [],
  172. // type = img-list 时,解析的元素List
  173. value_arr: []
  174. }
  175. },
  176. watch: {
  177. // 监听一些类型的 value 变动
  178. value: function(oldValue, newValue) {
  179. // img-list、audio-list、video-list、file-list、img-video-list
  180. if(this.type == 'img-list' || this.type == 'audio-list' || this.type == 'video-list' || this.type == 'file-list'
  181. || this.type == 'img-video-list' || this.type == 'text-list') {
  182. this.value_to_arr(this.value);
  183. }
  184. },
  185. },
  186. methods: {
  187. // 解析枚举
  188. parseJv: function() {
  189. for(let key in this.jv) {
  190. let value = this.jv[key];
  191. let color = '';
  192. //
  193. if(value.indexOf('[') != -1 && value.endsWith(']')) {
  194. let index = value.indexOf('[');
  195. color = value.substring(index + 1, value.length - 1);
  196. value = value.substring(0, index);
  197. // console.log(color + ' --- ' + value);
  198. }
  199. //
  200. if(isNaN(key) == false) {
  201. key = parseInt(key);
  202. }
  203. //
  204. this.jvList.push({
  205. key: key,
  206. value: value,
  207. color: color
  208. })
  209. }
  210. },
  211. // 解析 value 为 value_arr
  212. value_to_arr: function(value) {
  213. this.value_arr = sa.isNull(value) ? [] : value.split(',');
  214. for (var i = 0; i < this.value_arr.length; i++) {
  215. if(this.value_arr[i] == '' || this.value_arr[i].trim() == '') {
  216. sa.arrayDelete(this.value_arr, this.value_arr[i]);
  217. i--;
  218. }
  219. }
  220. },
  221. },
  222. created() {
  223. // console.log(this.br);
  224. if(this.type == 'fast-btn') {
  225. this.showBtns = this.show.split(',');
  226. for (var i = 0; i < this.showBtns.length; i++) {
  227. this.showBtns[i] = this.showBtns[i].trim();
  228. }
  229. }
  230. // 如果是枚举
  231. if(this.type == 'enum' || this.type == 'j' || this.type == 'switch') {
  232. this.parseJv();
  233. // console.log(this.jvList);
  234. }
  235. // 如果是 img-list 等
  236. if(this.type == 'img-list' || this.type == 'audio-list' || this.type == 'video-list' || this.type == 'file-list'
  237. || this.type == 'img-video-list' || this.type == 'text-list') {
  238. this.value_to_arr(this.value);
  239. }
  240. }
  241. }
  242. </script>
  243. <style scoped>
  244. </style>