changeConfig.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view class="pages">
  3. <uni-forms class="form" :value="dataObj" ref="formData" :rules="rules" :border="true"
  4. label-width="100">
  5. <uni-forms-item label="服务地址" name="url" :required="true" label-width="100">
  6. <input v-model="dataObj.url" type="text"
  7. class="uni-input" placeholder="例如:192.168.1.125" />
  8. </uni-forms-item>
  9. <uni-forms-item label="端口号" name="port" :required="true" label-width="100">
  10. <input v-model="dataObj.port" type="text"
  11. class="uni-input" placeholder="例如:8081" />
  12. </uni-forms-item>
  13. </uni-forms>
  14. <button class="but" type="default" :loading="loading" :disabled="loading" @tap="changePass">确认</button>
  15. </view>
  16. </template>
  17. <script>
  18. import {
  19. updateMobile,
  20. } from '@/common/api.js'
  21. import {
  22. api_config
  23. } from "@/config.js"
  24. export default {
  25. data() {
  26. return {
  27. dataObj: {
  28. url: "",
  29. port:""
  30. },
  31. loading: false,
  32. rules: {
  33. url: {
  34. rules: [{
  35. required: true,
  36. errorMessage: '请输入服务地址',
  37. },
  38. {
  39. validateFunction: function(rule, value, data, callback) {
  40. if (!(/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(data.url))) {
  41. callback('请输入正确的服务地址')
  42. }
  43. return true
  44. }
  45. }
  46. ]
  47. },
  48. port: {
  49. rules: [{
  50. required: true,
  51. errorMessage: '请输入端口号',
  52. },
  53. {
  54. validateFunction: function(rule, value, data, callback) {
  55. if (!(/^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/.test(data.port))) {
  56. callback('请输入正确端口号')
  57. }
  58. return true
  59. }
  60. }
  61. ]
  62. },
  63. }
  64. }
  65. },
  66. onReady() {
  67. this.$refs.formData.setRules(this.rules)
  68. },
  69. onShow() {
  70. this.dataObj.url = uni.getStorageSync("xjappserver").url
  71. this.dataObj.port = uni.getStorageSync("xjappserver").port
  72. },
  73. methods: {
  74. changePass() {
  75. this.$refs['formData'].validate().then(result => {
  76. uni.setStorageSync("xjappserver", {
  77. url:this.dataObj.url,
  78. port:this.dataObj.port,
  79. })
  80. console.log("+++++++++++++++++++++++++++++++")
  81. plus.nativeUI.toast('操作成功')
  82. console.log("+++++++++++++++++++++++++++++++")
  83. // api_config = this.dataObj.url+":"+this.dataObj.port
  84. console.log(api_config)
  85. setTimeout(() =>{
  86. /*uni.navigateBack({
  87. })*/
  88. uni.redirectTo({
  89. animationType: 'pop-in',
  90. animationDuration: 300,
  91. url: '../../pages/native/login',
  92. })
  93. },1000)
  94. })
  95. .catch(errors => {
  96. console.log("验证不通过=>", errors);
  97. })
  98. }
  99. }
  100. }
  101. </script>
  102. <style scoped lang="scss">
  103. .form {
  104. border-bottom: 1px solid #EEEEEE;
  105. }
  106. .but {
  107. width: 600rpx;
  108. margin-top: 420rpx;
  109. background-color: #0099FF;
  110. color: #fff;
  111. }
  112. </style>