sa-info.vue 7.8 KB

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