demo地址:
https://wanpan9527.github.io/#/

参考文档地址:
https://segmentfault.com/a/1190000018779991

核心代码:

  1. <template>
  2. <div id="app">
  3. <div class="main">
  4. <StyleEditor ref="styleEditor" v-bind.sync="currentStyle"></StyleEditor>
  5. <ResumeEditor ref="resumeEditor" :markdown = "currentMarkdown" :enableHtml="enableHtml"></ResumeEditor>
  6. </div>
  7. <BottomNav ref ="bottomNav" @on-pause="pauseAnimation" @on-skip="skipAnimation"></BottomNav>
  8. </div>
  9. </template>
  10. <script>
  11. import ResumeEditor from './components/resumeEditor'
  12. import StyleEditor from './components/styleEditor'
  13. import BottomNav from './components/bottomNav'
  14. import './assets/common.css'
  15. import fullStyle from './style.js'
  16. import my from './my.js'
  17. export default {
  18. name: 'app',
  19. components: {
  20. ResumeEditor,
  21. StyleEditor,
  22. BottomNav
  23. },
  24. data() {
  25. return {
  26. interval: 40,//写入字的速度
  27. currentStyle: {
  28. code: ''
  29. },
  30. enableHtml: false,//是否打造成HTML网页
  31. fullStyle: fullStyle,
  32. currentMarkdown: '',
  33. fullMarkdown: my,
  34. timer: null
  35. }
  36. },
  37. created() {
  38. this.makeResume();
  39. },
  40. methods: {
  41. // 暂停动画
  42. pauseAnimation(bool) {
  43. if(bool && this.timer){
  44. clearTimeout(this.timer);
  45. }else{
  46. this.makeResume();
  47. }
  48. },
  49. // 快速跳过动画
  50. skipAnimation(){
  51. if(this.timer){
  52. clearTimeout(this.timer);
  53. }
  54. let str = '';
  55. this.fullStyle.map((f) => {
  56. str += f;
  57. })
  58. setTimeout(() => {
  59. this.$set(this.currentStyle,'code',str);
  60. },100)
  61. this.currentMarkdown = my;
  62. this.enableHtml = true;
  63. this.$refs.bottomNav.playMusic();
  64. },
  65. // 加载动画
  66. makeResume: async function() {
  67. await this.writeShowStyle(0)
  68. await this.writeShowResume()
  69. await this.writeShowStyle(1)
  70. await this.writeShowHtml()
  71. await this.writeShowStyle(2)
  72. await this.$nextTick(() => {this.$refs.bottomNav.playMusic()});
  73. },
  74. // 打造成HTML网页
  75. writeShowHtml: function() {
  76. return new Promise((resolve, reject) => {
  77. this.enableHtml = true;
  78. resolve();
  79. })
  80. },
  81. // 写入css代码
  82. writeShowStyle(n) {
  83. return new Promise((resolve, reject) => {
  84. let showStyle = (async function() {
  85. let style = this.fullStyle[n];
  86. if (!style) return;
  87. //计算出数组每一项的长度
  88. let length = this.fullStyle.filter((f, i) => i <= n).map((it) => it.length).reduce((t, c) => t + c, 0);
  89. //当前要写入的长度等于数组每一项的长度减去当前正在写的字符串的长度
  90. let prefixLength = length - style.length;
  91. if (this.currentStyle.code.length < length) {
  92. let l = this.currentStyle.code.length - prefixLength;
  93. let char = style.substring(l, l + 1) || ' ';
  94. this.currentStyle.code += char;
  95. if (style.substring(l - 1, l) === '\n' && this.$refs.styleEditor) {
  96. this.$nextTick(() => {
  97. this.$refs.styleEditor.goBottom();
  98. })
  99. }
  100. this.timer = setTimeout(showStyle, this.interval);
  101. } else {
  102. resolve();
  103. }
  104. }).bind(this)
  105. showStyle();
  106. })
  107. },
  108. // 写入简历
  109. writeShowResume() {
  110. return new Promise((resolve, reject) => {
  111. let length = this.fullMarkdown.length;
  112. let showResume = () => {
  113. if (this.currentMarkdown.length < length) {
  114. this.currentMarkdown = this.fullMarkdown.substring(0, this.currentMarkdown.length + 1);
  115. let lastChar = this.currentMarkdown[this.currentMarkdown.length - 1];
  116. let prevChar = this.currentMarkdown[this.currentMarkdown.length - 2];
  117. if (prevChar === '\n' && this.$refs.resumeEditor) {
  118. this.$nextTick(() => {
  119. this.$refs.resumeEditor.goBottom()
  120. });
  121. }
  122. this.timer = setTimeout(showResume, this.interval);
  123. } else {
  124. resolve()
  125. }
  126. }
  127. showResume();
  128. })
  129. }
  130. }
  131. }
  132. </script>
  133. <style scoped>
  134. #app {
  135. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  136. -webkit-font-smoothing: antialiased;
  137. -moz-osx-font-smoothing: grayscale;
  138. }
  139. .main {
  140. position: relative;
  141. }
  142. html {
  143. min-height: 100vh;
  144. }
  145. * {
  146. transition: all 1.3s;
  147. }
  148. </style>
文档更新时间: 2019-05-10 14:29