keys.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // pages/keys/keys.js
  2. const app = getApp()
  3. const appConfig = require('../../config');
  4. const common = require('../../common');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. title:"创建公私钥",
  11. publicKey : "",
  12. privateKey : "",
  13. background: "",
  14. },
  15. savePrivateKey : function(){
  16. if(this.data.publicKey != "" && this.data.privateKey != ""){
  17. common.saveKeys(this)
  18. }
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. var _this = this;
  25. _this.setData({
  26. background: common.getBackground()
  27. });
  28. wx.setNavigationBarTitle({
  29. title: '创建公私钥'
  30. });
  31. //如果已经有公私钥了就退出当前页面
  32. var sslKeys = wx.getStorageSync(appConfig.storeKeys.sslKeys)
  33. var serverInfo = wx.getStorageSync(appConfig.storeKeys.serverInfo)
  34. if (serverInfo['sslKeys'] && sslKeys['publicKey'] == serverInfo['sslKeys']['publicKey']){
  35. wx.showModal({
  36. title: '温馨提示',
  37. content: '您已经创建了公私钥,如果丢失,请重置公私钥~',
  38. success: function(item){
  39. app.globalData.isReloadIcon = true;
  40. wx.navigateBack();
  41. }
  42. })
  43. return;
  44. }
  45. app.sslKeyRequestSync = res => {
  46. if (res && res.code == 0) {
  47. _this.setData({
  48. publicKey: res.data.publicKey,
  49. privateKey: res.data.privateKey,
  50. });
  51. }else if(res && res.code == 5) {
  52. //force update
  53. }
  54. }
  55. app.sslKeySaveSync = res => {
  56. //保存公私钥到本地
  57. wx.setStorageSync(appConfig.storeKeys.sslKeys, { 'publicKey': this.data.publicKey, 'privateKey': this.data.privateKey });
  58. //更新serverInfo中用户的公私钥
  59. var serverInfo = wx.getStorageSync(appConfig.storeKeys.serverInfo);
  60. serverInfo.sslKeys = { 'publicKey': this.data.publicKey, 'privateKey': this.data.privateKey };
  61. wx.setStorageSync(appConfig.storeKeys.serverInfo, serverInfo);
  62. app.globalData.isReloadIcon = true;
  63. wx.showModal({
  64. title: '温馨提示',
  65. content: res.msg || "保存成功",
  66. showCancel: false,
  67. success: function(item){
  68. wx.navigateBack();
  69. }
  70. })
  71. }
  72. common.genKeys(this);
  73. },
  74. /**
  75. * 生命周期函数--监听页面初次渲染完成
  76. */
  77. onReady: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面显示
  81. */
  82. onShow: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面隐藏
  86. */
  87. onHide: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面卸载
  91. */
  92. onUnload: function () {
  93. },
  94. /**
  95. * 页面相关事件处理函数--监听用户下拉动作
  96. */
  97. onPullDownRefresh: function () {
  98. },
  99. /**
  100. * 页面上拉触底事件的处理函数
  101. */
  102. onReachBottom: function () {
  103. },
  104. /**
  105. * 用户点击右上角分享
  106. */
  107. onShareAppMessage: function () {
  108. }
  109. })