add.vue 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <div class="subPage">
  3. <form class="mainForm">
  4. <ul>
  5. <li class="flex-h">
  6. <span>标题:<em>*</em></span>
  7. <div class="flex-item">
  8. <div style="width:50%">
  9. <el-input
  10. placeholder="请输入标题"
  11. v-model="postData.InfoName"
  12. clearable>
  13. </el-input>
  14. </div>
  15. </div>
  16. </li>
  17. <li class="flex-h">
  18. <span>跳转链接:<em>*</em></span>
  19. <div class="flex-item">
  20. <div style="width:50%">
  21. <el-input
  22. placeholder="请输入链接"
  23. v-model="postData.InfoUrl"
  24. clearable>
  25. </el-input>
  26. </div>
  27. </div>
  28. </li>
  29. <li class="flex-h">
  30. <span>对应案场:<em>*</em></span>
  31. <div class="flex-item">
  32. <div style="width:50%">
  33. <el-select v-model="postData.CaseId" placeholder="请选择">
  34. <el-option
  35. v-for="item in caseList"
  36. :key="item.CaseId"
  37. :label="item.CaseName"
  38. :value="item.CaseId">
  39. </el-option>
  40. </el-select>
  41. </div>
  42. </div>
  43. </li>
  44. <li style="text-align:center">
  45. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  46. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  47. </li>
  48. </ul>
  49. </form>
  50. </div>
  51. </template>
  52. <script>
  53. import { mapState, createNamespacedHelpers, mapActions } from 'vuex'
  54. const { mapActions: mapCmsActions } = createNamespacedHelpers('cms')
  55. export default {
  56. name: '',
  57. data () {
  58. return {
  59. ajaxOff: true,
  60. postData: {
  61. InfoName: '',
  62. InfoUrl: '',
  63. OrgId: '',
  64. CaseId: '',
  65. LocationId: 'index'
  66. }
  67. }
  68. },
  69. components: {},
  70. created () {
  71. this.updateLocationInfo()
  72. this.updateSystemInfo().then(() => {
  73. this.postData.CaseId = this.defaultCaseId
  74. })
  75. },
  76. computed: {
  77. ...mapState({
  78. // positionList: x => x.cms.location,
  79. OrgId: x => x.app.user.OrgId,
  80. defaultCaseId: x => x.app.cases.default,
  81. caseList: x => x.app.cases.list
  82. })
  83. },
  84. methods: {
  85. ...mapCmsActions(['updateLocationInfo']),
  86. ...mapActions(['updateSystemInfo']),
  87. submit () {
  88. if (this.ajaxOff) {
  89. if (this.postData.InfoName === '') {
  90. this.$message({
  91. message: '标题不能为空',
  92. type: 'error',
  93. })
  94. return false
  95. }
  96. if (this.postData.InfoUrl === '') {
  97. this.$message({
  98. message: '链接地址不能为空',
  99. type: 'error',
  100. })
  101. return false
  102. }
  103. // var reg = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/ // eslint-disable-line
  104. // if (!reg.test(this.postData.InfoUrl)) {
  105. // this.$message({
  106. // message: '链接地址格式不正确',
  107. // type: 'error',
  108. // })
  109. // return false
  110. // }
  111. var strRegex = /^(ftp|https?)\:\/\/([\w\_\-]+)\.([\w\-]+[\.]?)*[\w]+\.[a-zA-Z]{2,10}(.*)/ // eslint-disable-line
  112. if (this.postData.InfoUrl.match(strRegex) === null) {
  113. this.$message({
  114. message: '链接地址格式不正确',
  115. type: 'error',
  116. })
  117. return false
  118. }
  119. this.postData.OrgId = this.OrgId
  120. this.ajaxOff = false
  121. this.$ajax(this.$api.cms.addInfo.url, {
  122. method: this.$api.cms.addInfo.method,
  123. data: this.postData
  124. }).then(res => {
  125. this.ajaxOff = true
  126. this.$message({
  127. message: '添加成功',
  128. type: 'success',
  129. duration: 1000
  130. })
  131. this.$router.push({ name: 'indexMsg' })
  132. }).catch(msg => {
  133. this.ajaxOff = true
  134. })
  135. }
  136. },
  137. cancel () {
  138. this.$router.go(-1)
  139. }
  140. }
  141. }
  142. </script>
  143. <!-- Add "scoped" attribute to limit CSS to this component only -->
  144. <style lang="scss" scoped>
  145. </style>