settings.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view class="settings">
  3. <view class="title">服务器配置</view>
  4. <view class="form-item">
  5. <text class="label">服务器 IP</text>
  6. <input
  7. class="input"
  8. v-model="ip"
  9. placeholder="请输入服务器 IP,如 192.168.111.200"
  10. />
  11. </view>
  12. <view class="form-item">
  13. <text class="label">端口</text>
  14. <input
  15. class="input"
  16. v-model="port"
  17. placeholder="请输入端口,如 8800"
  18. type="number"
  19. />
  20. </view>
  21. <button class="btn-save" @click="save">保存</button>
  22. <button class="btn-reset" @click="reset">恢复默认</button>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. ip: '',
  30. port: '',
  31. DEFAULT_IP: '192.168.111.200',
  32. DEFAULT_PORT: '8800',
  33. };
  34. },
  35. onLoad() {
  36. // #ifdef APP-PLUS
  37. this.ip = plus.storage.getItem('ip') || this.DEFAULT_IP;
  38. this.port = plus.storage.getItem('port') || this.DEFAULT_PORT;
  39. // #endif
  40. },
  41. methods: {
  42. save() {
  43. if (!this.ip) {
  44. uni.showToast({ title: '请输入 IP', icon: 'none' });
  45. return;
  46. }
  47. if (!this.port) {
  48. uni.showToast({ title: '请输入端口', icon: 'none' });
  49. return;
  50. }
  51. // #ifdef APP-PLUS
  52. plus.storage.setItem('ip', this.ip);
  53. plus.storage.setItem('port', this.port);
  54. // #endif
  55. uni.showToast({ title: '保存成功', icon: 'success' });
  56. setTimeout(() => {
  57. uni.reLaunch({ url: '/pages/sample/webView' });
  58. }, 800);
  59. },
  60. reset() {
  61. this.ip = this.DEFAULT_IP;
  62. this.port = this.DEFAULT_PORT;
  63. // #ifdef APP-PLUS
  64. plus.storage.setItem('ip', this.DEFAULT_IP);
  65. plus.storage.setItem('port', this.DEFAULT_PORT);
  66. // #endif
  67. uni.showToast({ title: '已恢复默认', icon: 'none' });
  68. },
  69. },
  70. };
  71. </script>
  72. <style scoped>
  73. .settings {
  74. padding: 40rpx 30rpx;
  75. }
  76. .title {
  77. font-size: 40rpx;
  78. font-weight: bold;
  79. margin-bottom: 50rpx;
  80. color: #333;
  81. }
  82. .form-item {
  83. margin-bottom: 30rpx;
  84. }
  85. .label {
  86. display: block;
  87. font-size: 28rpx;
  88. color: #666;
  89. margin-bottom: 12rpx;
  90. }
  91. .input {
  92. border: 1px solid #ddd;
  93. border-radius: 8rpx;
  94. padding: 20rpx;
  95. font-size: 30rpx;
  96. background: #fff;
  97. }
  98. .btn-save {
  99. margin-top: 40rpx;
  100. background: #0039a6;
  101. color: #fff;
  102. border-radius: 8rpx;
  103. }
  104. .btn-reset {
  105. margin-top: 20rpx;
  106. background: #f5f5f5;
  107. color: #666;
  108. border-radius: 8rpx;
  109. }
  110. </style>