unsubscribe.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. var content = {
  2. 'cn':{
  3. item1:'退订',
  4. btn:'确定',
  5. item2:'您正在进行退订操作',
  6. item3:'退订后,您将不再收到电子邮件提醒。',
  7. item4:'如果您有时间,请告诉我们您退订的原因:',
  8. item5:"我不想再收到这些邮件了",
  9. item6:"我从来没有注册过这个邮件列表",
  10. item7:"这些邮件不合适",
  11. item8:"这些邮件是垃圾邮件,应该上报",
  12. item9:"其他(请填写原因)",
  13. success:'成功',
  14. },
  15. 'en':{
  16. item1:'Unsubscribe',
  17. btn:'Confirm',
  18. item2:'Your unsubscribe is in progress',
  19. item3:'After unsubscribing, you will no longer receive email reminders.',
  20. item4:'If you have a moment, please tell us the reason for your unsubscribe:',
  21. item5:"I no longer want to receive these emails",
  22. item6:"I never signed up for this mailing list",
  23. item7:"The emails are inappropriate",
  24. item8:"The emails are spam and should be reported",
  25. item9:"Others (fill in reason below)",
  26. success:'success',
  27. }
  28. };
  29. let config = {
  30. Pattern: {
  31. Password: /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?!.*([~!@&%$^\\(\\)#_]).*\\1.*\\1.*\\1)[A-Za-z0-9~!@&%$^\\(\\)#_]{8,16}$/,
  32. }
  33. };
  34. let vm = new Vue({
  35. el: "#unsubscribe",
  36. data(){
  37. return{
  38. ho:'',
  39. //多语言
  40. langList: {
  41. en: "ENGLISH",
  42. cn: "中文简体"
  43. },
  44. language: "en",
  45. lang:{},
  46. params: {
  47. reasons:[],
  48. reasonsOther:'',
  49. unsubscribe:'',
  50. },
  51. rules: {
  52. password: [
  53. {
  54. validator: (rule, value, callback) => {
  55. if (config.Pattern.Password.test(value)) {
  56. callback();
  57. } else {
  58. callback(new Error(this.lang.item2));
  59. }
  60. },
  61. trigger: "blur"
  62. }
  63. ],
  64. password1: [
  65. {
  66. validator: (rule, value, callback) => {
  67. if (value === '') {
  68. callback(new Error(this.lang.item4));
  69. } else if (value !== this.params.password) {
  70. callback(new Error(this.lang.item5));
  71. } else {
  72. callback();
  73. }
  74. },
  75. trigger: "blur"
  76. }
  77. ]
  78. }
  79. }
  80. },
  81. computed: {
  82. AccessToken(){
  83. return{
  84. 'Access-Token': window.location.search.split('?token=')[1]
  85. }
  86. }
  87. },
  88. methods: {
  89. // 语言切换函数
  90. chooseLang (key) {
  91. this.lang = content[key];
  92. this.language = key;
  93. },
  94. // 发送
  95. send: async function () {
  96. this.$refs["params"].validate(async valid => {
  97. if (valid) {
  98. let reason = '';
  99. this.params.reasons.forEach(item=>{
  100. if (item && item != '其他(请填写原因)' && item != 'Others (fill in reason below)') {
  101. reason = reason + item + ';'
  102. }
  103. });
  104. if (this.params.reasonsOther) {
  105. reason = reason + this.params.reasonsOther;
  106. }
  107. let unsubscribe = '';
  108. unsubscribe = this.params.unsubscribe.replace(/%25/g,'%').replace(/%2B/g,'\+').replace(/%20/g,' ').replace(/%2F/g,'\/').replace(/%3F/g,'\?');
  109. let hostParts = window.location.host.split('.');
  110. let tld = hostParts.slice(2).join('.') || 'com';
  111. axios.post('https://secure.' + this.ho + '.' + tld + '/email/unsubscribe/add', {
  112. unsubscribe:unsubscribe,
  113. reason:reason
  114. //参数
  115. }).then(res => {//请求成功后的处理函数
  116. if (res.data.code == 200) {
  117. this.$message({
  118. message: this.lang.success,
  119. type: 'success'
  120. });
  121. setTimeout(() => {
  122. window.location.href = 'https://secure.' + this.ho + '.' + tld
  123. }, 2000);
  124. } else {
  125. this.$message.error(res.data.msg);
  126. }
  127. }).catch(err => { //请求失败后的处理函数
  128. })
  129. } else {
  130. return false;
  131. }
  132. });
  133. },
  134. },
  135. mounted() {
  136. this.ho = window.location.host.split('.')[1];
  137. this.params.unsubscribe = window.location.search.split('?unsubscribe=')[1];
  138. var jsSrc =(navigator.language || navigator.browserLanguage).toLowerCase();
  139. if(jsSrc.indexOf('zh') >= 0){
  140. this.language = 'cn'
  141. this.lang = content['cn'];
  142. }else{
  143. this.language = 'en'
  144. this.lang = content['en'];
  145. }
  146. }
  147. });