index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view>
  3. <!--/*
  4. ***HotApp云笔记,基于HotApp小程序统计云后台
  5. ***免费云后台申请地址 https://weixin.hotapp.cn/cloud
  6. ***API 文档地址:https://weixin.hotapp.cn/api
  7. ***小程序技术讨论QQ群:173063969
  8. */-->
  9. <!-- index.wxml -->
  10. <form @submit="onSubmit" @reset="">
  11. <view class="container">
  12. <view class="title"><input name="title" placeholder-class="placeholder" placeholder="在此输入标题(可选)" :value="item.value.title" /></view>
  13. <view class="row">
  14. <textarea class="text" placeholder-class="placeholder" name="content" :focus="focus" :value="item.value.content" placeholder="点击添加文本" />
  15. </view>
  16. <view class="date placeholder">
  17. {{ item.update_date }}
  18. </view>
  19. <view class="bottom">
  20. <button formType="submit" class="btn success">保存</button>
  21. <button class="btn del" @tap="onDelete">删除</button>
  22. </view>
  23. </view>
  24. </form>
  25. </view>
  26. </template>
  27. <script>
  28. /*
  29. ***HotApp云笔记,基于HotApp小程序统计云后台
  30. ***免费云后台申请地址 https://weixin.hotapp.cn/cloud
  31. ***API 文档地址:https://weixin.hotapp.cn/api
  32. ***小程序技术讨论QQ群:173063969
  33. */
  34. var app = getApp();
  35. export default {
  36. data() {
  37. return {
  38. item: {
  39. key: '',
  40. value: {
  41. title: '',
  42. content: ''
  43. },
  44. create_time: '',
  45. update_time: '',
  46. state: 1
  47. },
  48. isNew: false,
  49. focus: true
  50. };
  51. }
  52. /**
  53. * 页面首次加载事件
  54. */,
  55. onLoad: function (options) {
  56. var item = this.item;
  57. item.key = options.key;
  58. this.setData({
  59. item: item
  60. });
  61. },
  62. /**
  63. * 页面渲染事件
  64. */
  65. onShow: function () {
  66. this.loadData(this.item.key);
  67. },
  68. methods: {
  69. /**
  70. * 保存数据事件
  71. */
  72. onSubmit: function (event) {
  73. var item = this.item;
  74. item.value.title = event.detail.value.title;
  75. item.value.content = event.detail.value.content;
  76. this.setData({
  77. item: item
  78. });
  79. this.saveData();
  80. },
  81. /**
  82. * 请求服务器保存数据
  83. */
  84. saveData: function () {
  85. var item = this.item;
  86. var now = Date.parse(new Date()) / 1000;
  87. item.update_time = now;
  88. this.setData({
  89. item: item
  90. });
  91. app.globalData.store(this.item, function (res) {
  92. if (res) {
  93. uni.showToast({
  94. title: '保存成功'
  95. });
  96. //返回首页
  97. uni.navigateBack();
  98. } else {
  99. uni.showToast({
  100. title: '保存失败'
  101. });
  102. }
  103. });
  104. },
  105. /**
  106. * 删除记事本事件
  107. */
  108. onDelete: function (event) {
  109. app.globalData.destroy(this.item, function (res) {
  110. if (res) {
  111. uni.showToast({
  112. title: '删除成功'
  113. });
  114. uni.redirectTo({
  115. url: '../index/index'
  116. });
  117. } else {
  118. uni.showToast({
  119. title: '删除失败'
  120. });
  121. }
  122. });
  123. },
  124. /**
  125. * 获取数据
  126. */
  127. loadData: function (key) {
  128. var that = this;
  129. app.globalData.show(this.item.key, function (res) {
  130. that.setData({
  131. item: res
  132. });
  133. });
  134. }
  135. }
  136. };
  137. </script>
  138. <style>
  139. @import './index.css';
  140. </style>