reset.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // pages/keys/keys.js
  2. const app = getApp()
  3. const appConfig = require('../../config');
  4. const common = require('../../common');
  5. const utils = require('../../utils/util');
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. title:"重置私钥",
  12. publicKey: "",
  13. privateKey: "",
  14. opt: "",
  15. background: "",
  16. },
  17. textareaAInput : function(e){
  18. var name = e.target.dataset.id;
  19. var data = {};
  20. data[name] = e.detail.value;
  21. this.setData(data);
  22. },
  23. resetPrivateKey: function () {
  24. var _this = this;
  25. wx.showModal({
  26. title: '是否要重置公私钥',
  27. content: '公私钥将重新生成,您保存的密码将无法解密,请确认是否要进行操作',
  28. confirmText: '重置',
  29. success: function (item) {
  30. if (item.confirm) {
  31. var sslKeys = utils.genSslKey();
  32. common.saveClientPublicKey(_this, sslKeys['publicKey'], sslKeys['privateKey'])
  33. }
  34. }
  35. })
  36. },
  37. savePrivateKey: function () {//直接保存用户生成密钥,需要校验公私钥
  38. var _this = this;
  39. //校验公私钥
  40. if (!utils.verifySslKey(_this.data.publicKey, _this.data.privateKey)) {
  41. app.warning("您的公私钥不匹配,请查证后再试~");
  42. return;
  43. }
  44. wx.showModal({
  45. title: '是否要使用自己公私钥',
  46. content: '公私钥保存后,您保存的密码可能无法解密,请确认是否要进行操作',
  47. confirmText: '保存',
  48. success: function (item) {
  49. if (item.confirm) {
  50. common.saveClientPublicKey(_this, _this.data.publicKey, _this.data.privateKey)
  51. }
  52. }
  53. })
  54. },
  55. /**
  56. * 生命周期函数--监听页面加载
  57. */
  58. onLoad: function (options) {
  59. var _this = this;
  60. _this.setData({
  61. background: utils.getBackground()
  62. });
  63. wx.setNavigationBarTitle({
  64. title: '重置私钥'
  65. });
  66. var serverInfo = wx.getStorageSync("serverInfo");
  67. this.setData({
  68. publicKey: utils.getPublicKey(),
  69. privateKey: utils.getPrivateKey(),
  70. });
  71. app.sslKeySaveSync = res => {
  72. if(!res || (res.code && res.code > 0)){
  73. app.warning(res.msg || "更新失败");
  74. return;
  75. }
  76. this.data.publicKey = res.data.publicKey;
  77. this.data.privateKey = res.data.privateKey;
  78. this.setData({
  79. publicKey : this.data.publicKey,
  80. privateKey : this.data.privateKey
  81. });
  82. //更新本地公私钥
  83. wx.setStorageSync(appConfig.storeKeys.sslKeys, { 'publicKey': this.data.publicKey, 'privateKey': this.data.privateKey });
  84. //更新serverInfo中用户的公私钥
  85. var serverInfo = wx.getStorageSync(appConfig.storeKeys.serverInfo);
  86. serverInfo.sslKeys = { 'publicKey': this.data.publicKey, 'privateKey': this.data.privateKey };
  87. wx.setStorageSync(appConfig.storeKeys.serverInfo, serverInfo);
  88. app.globalData.isReloadLists = true;
  89. wx.showModal({
  90. title: '温馨提示',
  91. content: '请将您的私钥拷贝出来保存到一个安全的地方(点击确定内容将自动复制),以供以后恢复密码使用~',
  92. success:function(item){
  93. if(item.confirm) {
  94. wx.setClipboardData({
  95. data: _this.data.privateKey,
  96. success: function (res) {
  97. wx.getClipboardData({
  98. success: function (res) {
  99. }
  100. });
  101. },
  102. fail: function () {
  103. app.toast("复制失败");
  104. }
  105. });
  106. }
  107. }
  108. });
  109. app.globalData.isReloadIcon = true;
  110. }
  111. },
  112. /**
  113. * 生命周期函数--监听页面初次渲染完成
  114. */
  115. onReady: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面显示
  119. */
  120. onShow: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面隐藏
  124. */
  125. onHide: function () {
  126. },
  127. /**
  128. * 生命周期函数--监听页面卸载
  129. */
  130. onUnload: function () {
  131. },
  132. /**
  133. * 页面相关事件处理函数--监听用户下拉动作
  134. */
  135. onPullDownRefresh: function () {
  136. common.genKeys(this);
  137. },
  138. /**
  139. * 页面上拉触底事件的处理函数
  140. */
  141. onReachBottom: function () {
  142. },
  143. /**
  144. * 用户点击右上角分享
  145. */
  146. onShareAppMessage: function () {
  147. }
  148. })