elementMixin.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. const mixin = {
  2. data() {
  3. /* element form校验相关*/
  4. // 密码必须为6-18位字母、数字
  5. const passwordValid = (rule, value, callback) => {
  6. if (!/^(?![^a-zA-Z]+$)(?!\D+$)/.test(value)) {
  7. callback(new Error('6-18位字母、数字'))
  8. } else {
  9. callback()
  10. }
  11. }
  12. // 大于0的整数
  13. const upZeroInt = (rule, value, callback) => {
  14. if (!/^\+?[1-9]\d*$/.test(value)) {
  15. callback(new Error('大于0的整数'))
  16. } else {
  17. callback()
  18. }
  19. }
  20. const upZeroIntCanNull = (rule, value, callback) => {
  21. if (!value) {
  22. callback()
  23. } else {
  24. if (!/^\+?[1-9]\d*$/.test(value)) {
  25. callback(new Error('大于0的整数'))
  26. } else {
  27. callback()
  28. }
  29. }
  30. }
  31. const validatePass = (rule, value, callback) => {
  32. if (value === '') {
  33. callback(new Error('请输入密码'))
  34. } else {
  35. callback()
  36. }
  37. }
  38. return {
  39. /* table*/
  40. pageNumMixin: 1,
  41. pageSizeMixin: 10,
  42. pageTotalMixin: 0,
  43. tableDataMixin: [],
  44. rowDeleteIdArrMixin: [],
  45. loadingIdMixin: null,
  46. /* 表单*/
  47. formModelMixin: {},
  48. subFormMixin: {},
  49. searchFormMixin: {},
  50. /* 表单校验*/
  51. formRulesMixin: {
  52. isNotNull: [{ required: true, message: '该字段不能为空', trigger: 'blur' }],
  53. isNotNullSecond: [{ required: true, message: '不能为空', trigger: 'blur' }],
  54. mLength8: [
  55. { required: true, message: '该字段不能为空', trigger: 'blur' },
  56. { max: 8, message: '最长为8个字符', trigger: 'blur' }
  57. ],
  58. minLength7: [
  59. { required: true, message: '该字段不能为空', trigger: 'blur' },
  60. { min: 7, message: '最小7个字符', trigger: 'blur' }
  61. ],
  62. length17: [
  63. { required: true, message: '该字段不能为空', trigger: 'blur' },
  64. { min: 17, max: 17, message: '长度为17个字符', trigger: 'blur' }
  65. ],
  66. desc: [{ validator: validatePass, trigger: 'blur' }],
  67. upZeroInt: [{ validator: upZeroInt, trigger: 'blur' }],
  68. upZeroIntCanNull: [{ validator: upZeroIntCanNull, trigger: 'blur' }],
  69. passwordValid: [{ validator: passwordValid, trigger: 'blur' }]
  70. },
  71. /* 时间packing相关*/
  72. datePickerOptions: {
  73. disabledDate: (time) => {
  74. return time.getTime() < Date.now() - 86400000
  75. }
  76. },
  77. startEndArrMixin: [],
  78. startEndArrSubMixin: [],
  79. /* dialog相关*/
  80. dialogTitleMixin: '添加',
  81. detailDialogMixin: false,
  82. isDialogEditMixin: false,
  83. dialogVisibleMixin: false,
  84. tableLoadingMixin: false,
  85. /* 级联相关*/
  86. cascaderKeyMixin: 1,
  87. SetKesDeptMixin: {
  88. value: 'id',
  89. expandTrigger: 'hover',
  90. label: 'label',
  91. children: 'children'
  92. },
  93. SetKesDeptMixinNoStrictlyMixin: {
  94. value: 'id',
  95. expandTrigger: 'hover',
  96. label: 'label',
  97. children: 'children',
  98. checkStrictly: true
  99. },
  100. SetKesDeptMixinNoStrictly: {
  101. value: 'id',
  102. expandTrigger: 'hover',
  103. label: 'label',
  104. children: 'children',
  105. checkStrictly: true
  106. },
  107. cascaderOptionsMixinOne: [],
  108. cascaderOptionsMixin: [],
  109. /* 树相关*/
  110. treeDataMixin: [],
  111. defaultProps: {
  112. children: 'children',
  113. label: 'label'
  114. }
  115. }
  116. },
  117. methods: {
  118. /* 级联*/
  119. casHandleChangeMixin() {
  120. // 解决目前级联选择器搜索输入报错问题
  121. ++this.cascaderKey
  122. },
  123. /*
  124. * 通知弹框
  125. * message:通知的内容
  126. * type:通知类型
  127. * duration:通知显示时长(ms)
  128. * */
  129. elMessageMixin(message, type) {
  130. type = type || 'success'
  131. this.$message({
  132. showClose: true,
  133. message: message || '成功',
  134. type: type,
  135. center: false
  136. })
  137. },
  138. /*
  139. * loading加载框
  140. * 调用后通过 this.loadingIdMixin.close() 进行关闭
  141. * */
  142. elLoadingMixin() {
  143. this.loadingIdMixin = this.$loading({
  144. lock: true,
  145. text: '数据载入中',
  146. spinner: 'el-icon-loading',
  147. background: 'rgba(0, 0, 0, 0.1)'
  148. })
  149. },
  150. /*
  151. * 提示
  152. * message: 提示内容
  153. * type:提示类型
  154. * title:提示标题
  155. * duration:提示时长(ms)
  156. * */
  157. elNotifyMixin(message, type, title, duration) {
  158. type = type || 'success'
  159. this.$notify[type]({
  160. title: title || '提示',
  161. message: message || '请传入提示消息',
  162. position: 'top-right',
  163. duration: duration || 2500,
  164. offset: 40
  165. })
  166. },
  167. /*
  168. 确认弹框(没有取消按钮)
  169. * title:提示的标题
  170. * message:提示的内容
  171. * return Promise
  172. * */
  173. elConfirmNoCancelBtnMixin(title, message) {
  174. return this.$confirm(message || '你确定要删除吗', title || '确认框', {
  175. confirmButtonText: '确定',
  176. cancelButtonText: '取消',
  177. showCancelButton: false,
  178. type: 'warning'
  179. }).catch(() => {})
  180. },
  181. /*
  182. * 确认弹框
  183. * title:提示的标题
  184. * message:提示的内容
  185. * return Promise
  186. * */
  187. elConfirmMixin(title, message) {
  188. return this.$confirm(message || '你确定要删除吗', title || '确认框', {
  189. confirmButtonText: '确定',
  190. cancelButtonText: '取消',
  191. type: 'warning'
  192. })
  193. }
  194. }
  195. }
  196. const detailDialogMixin = false
  197. export default mixin