QSInputsMixin.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import _app from './app.js';
  2. const publicProps = {
  3. name: {
  4. type: String,
  5. default: ''
  6. },
  7. variableName: {
  8. type: String,
  9. default: ''
  10. },
  11. required: {
  12. type: Boolean,
  13. default: false
  14. },
  15. value: {
  16. type: [String, Array, Number, Object, Boolean],
  17. deault: ''
  18. },
  19. titleFlex: {
  20. type: [Number, String],
  21. default: 1
  22. },
  23. contentFlex: {
  24. type: [Number, String],
  25. default: 4
  26. },
  27. titleStyle: {
  28. type: String,
  29. default: ''
  30. },
  31. contentStyle: {
  32. type: String,
  33. default: ''
  34. },
  35. titleLayout: {
  36. type: String,
  37. default: 'default'
  38. },
  39. contentLayout: {
  40. type: String,
  41. default: 'default'
  42. },
  43. boxStyle: {
  44. type: String,
  45. default: ''
  46. },
  47. title: {
  48. type: String,
  49. default: ''
  50. },
  51. titleHide: {
  52. type: Boolean,
  53. default: false
  54. },
  55. fontSize: {
  56. type: Number,
  57. default: 30
  58. },
  59. width: {
  60. type: String,
  61. default: '100%'
  62. },
  63. customId: {
  64. type: [String, Number, Object],
  65. default: ''
  66. },
  67. requiredSign: {
  68. type: String,
  69. default: '*'
  70. },
  71. layout: {
  72. type: String,
  73. default: 'row'
  74. },
  75. itemDisabled: {
  76. type: Boolean,
  77. default: false
  78. },
  79. itemLayout: {
  80. type: String,
  81. default: ''
  82. },
  83. titleColor: {
  84. type: String,
  85. default: '#999'
  86. }
  87. }
  88. export default ({
  89. QSInputsType
  90. } = {}) => {
  91. return {
  92. name: 'QS_' + QSInputsType,
  93. props: {
  94. ...publicProps
  95. },
  96. model: {
  97. prop: 'value',
  98. event: 'input'
  99. },
  100. data() {
  101. return {
  102. type: QSInputsType
  103. }
  104. },
  105. created() {
  106. switch (QSInputsType){
  107. case _app.typeObj.pics:
  108. this.setForm(this.value || this.itemArray);
  109. break;
  110. case _app.typeObj.infinitePics:
  111. this.setForm(this.value || this.itemArray);
  112. break;
  113. default:
  114. this.setForm(this.value);
  115. break;
  116. }
  117. },
  118. computed: {
  119. contentLayout_computed() {
  120. switch (this.contentLayout){
  121. case 'center':
  122. return 'flex_row_c_c';
  123. break;
  124. case 'left':
  125. return 'flex_row_none_c';
  126. break;
  127. case 'right':
  128. return 'flex_row_e_c';
  129. break;
  130. default:
  131. if(this.layout === 'column') {
  132. return 'flex_row_none_c';
  133. }else{
  134. return 'flex_row_e_c';
  135. }
  136. break;
  137. }
  138. },
  139. itemLayout_computed() {
  140. switch (this.itemLayout){
  141. case 'center':
  142. return 'flex_row_c_c';
  143. break;
  144. case 'left':
  145. return 'flex_row_none_c';
  146. break;
  147. case 'right':
  148. return 'flex_row_e_c';
  149. break;
  150. default:
  151. if(this.layout === 'column') {
  152. return 'flex_row_none_c';
  153. }else{
  154. return 'flex_row_e_c';
  155. }
  156. break;
  157. }
  158. }
  159. },
  160. beforeDestroy() {
  161. this.delForm();
  162. },
  163. methods: {
  164. setValue(value) {
  165. this.$emit('input', value);
  166. this.$emit('change', value);
  167. this.setForm(value);
  168. },
  169. delForm() {
  170. if (this.name && this.variableName) {
  171. _app.delForm({
  172. name: this.name,
  173. variableName: this.variableName,
  174. })
  175. }
  176. },
  177. setForm(value) {
  178. if (this.name && this.variableName) {
  179. _app.setForm({
  180. title: this.title,
  181. name: this.name,
  182. variableName: this.variableName,
  183. value,
  184. type: this.type,
  185. required: this.required,
  186. verifyFc: this.verifyFc,
  187. verifyType: this.verifyType,
  188. customId: this.customId,
  189. upLoadData: this.upLoadData //图片上传自定义数据
  190. })
  191. }
  192. },
  193. setData(data) {
  194. if(this.$refs.inputsRef && this.$refs.inputsRef.setData && typeof this.$refs.inputsRef.setData === 'function') {
  195. this.$refs.inputsRef.setData(data);
  196. }else{
  197. _app.log('not find ref or setData!');
  198. }
  199. }
  200. }
  201. }
  202. }