5 | Stick me 6 | {{ pinPadding }} 7 | px from the {{ direction }} of the page 8 |
9 |{{ time }}
12 | 13 |
14 | 以下是自定义全局组件
16 |这是第1个问题哈哈自定义html
',Q2:'
',Q3:"这是第3个问题这是第3个问题这是第3个问题",Q4:"这是第4个这这是第4个问题题问题",Q5:'这是第5个问题
',Q6:"这是第6个问第7个题",Q7:"这是第7个问题第7个第7个",Q8:"问题结束",Q9:"结束语"},h={A1:"这是第1个回答选项",A2:"这是第2个答选项回答选项",A3:"这是第3个回答选项",A4:"这是第4个回答选项答",A5:"这答选项是第5个回答选项答选项",A6:"这是第6个回答选项",A7:"这是第7个回答选项这是第7个回答选项",A8:"这是第8个回答选项",A9:"这是第9个回答选项答选项",A10:"这是第10个回答选项",A11:"这是第11个回答选项答选项答选项",A12:"这是第12个回答选项",A13:"这是第13个回答选项答选项答选项答选项",A14:"这是第14个回答选项",A15:"这是第15个回答选项答选项",A16:"这是第16个回答选项"},w={Q1:{A1:"Q6",A2:"Q3",A3:"Q7",A4:"Q5"},Q2:{A5:"Q4",A6:"Q3",A7:"Q8",A8:"Q1"},Q3:{A9:"Q2",A10:"Q4",A11:"Q8"},Q4:{A5:"Q1",A7:"Q8",A2:"Q3",A8:"Q4"},Q5:{A1:"Q5",A3:"Q6",A9:"Q7",A11:"Q8"},Q6:{A4:"Q2",A6:"Q6",A10:"Q4",A12:"Q7"},Q7:"Q8",Q8:"Q9"};function N(){let n=window.pageYOffset;const e=document.documentElement.offsetHeight-document.documentElement.clientHeight;window.requestAnimationFrame||(window.requestAnimationFrame=function(l){return setTimeout(l,17)});function o(){if(n=n+(e-n)/8,Math.abs(e-n)<2){window.scrollTo(0,e);return}window.scrollTo(0,n),requestAnimationFrame(o)}o()}const O=n=>{var e;return(e=j(n))==null?void 0:e.getBoundingClientRect()},v=n=>{var o;const e=c();return e.value=((o=O(n))==null?void 0:o.height)||0,e},S=k(()=>{const n=R(),e=c(),o=p([]),l=v(e),m=c(!0),r=c("对方正在输入中...");let u=0,f=0,i=p([]),a=w.Q1;window.scroll2Bottom=()=>N();const Q=()=>Math.ceil((Math.random()*2+1.5)*1e3),x=()=>Math.ceil(Math.random()+.5*1e3),b=()=>{n.back()},g=async()=>{await q(),l.value=v(e).value,window.scroll2Bottom()},T=()=>{console.log("聊天结束"),m.value=!1},A=(t,M)=>{o.push({message:t,direction:M})},d=t=>{if(A(E[t],"left"),a=w[t],!a)return T();typeof a=="string"?u=setTimeout(()=>{d(a),g()},Q()):i=Object.keys(a)},y=t=>{A(h[t],"right"),i=[],r.value="请稍等...",f=setTimeout(()=>{r.value="对方正在输入中..."},x()),u=setTimeout(()=>{d(typeof a=="string"?a:a[t]),g()},Q())},B=()=>o.length>0&&s("div",{class:"chat-wrapper",style:{marginBottom:l.value+50+"px"}},[o.map(t=>s("li",{class:["flex pd10 align-start",t.direction==="left"?"justify-start":"justify-end"]},[t.direction==="left"?s("div",{class:"avatar"},null):null,s("div",{class:["mg-l10 bubble",t.direction==="left"?"bubble-left":"bubble-right"]},[s("p",{class:"bgfff lh20 fs12",innerHTML:t.message},null)]),t.direction==="right"?s("div",{class:"avatar"},null):null]))]),L=()=>i.length>0?s("div",{class:"answers-wrapper flex flex-wrap max640",ref:e},[i.map(t=>s("div",{class:"btnbox col-6 flex"},[s("div",{class:"flex flex-center btn",onClick:()=>y(t)},[h[t]])]))]):s("div",{class:"answers-wrapper max640"},[H(s("div",{class:"loadingtxt fs12 lh20 mg10 text-center"},[r.value]),[[F,m.value]])]);return C(()=>{d("Q1")}),D(()=>{clearTimeout(u),clearTimeout(f)}),()=>s("div",{class:"pd-nav"},[s(z,{fixed:!0,title:"聊天室","left-arrow":!0,"onClick-left":b},null),B(),L()])});export{S as default};
2 |
--------------------------------------------------------------------------------
/src/assets/css/main.less:
--------------------------------------------------------------------------------
1 | input {
2 | border: 1px solid #dedede;
3 | border-radius: 5px;
4 | outline: none;
5 | text-indent: 2px;
6 | height: 30px;
7 | line-height: 26px;
8 | }
9 |
10 | .mg5 {
11 | margin: 5px;
12 | }
13 |
14 | .mg10 {
15 | margin: 10px;
16 | }
17 |
18 | .mg15 {
19 | margin: 15px;
20 | }
21 |
22 | .mg20 {
23 | margin: 20px;
24 | }
25 |
26 | .mg-t0 {
27 | margin-top: 0;
28 | }
29 |
30 | .mg-r0 {
31 | margin-right: 0;
32 | }
33 |
34 | .mg-b0 {
35 | margin-bottom: 0;
36 | }
37 |
38 | .mg-l0 {
39 | margin-left: 0;
40 | }
41 |
42 | .mg-t5 {
43 | margin-top: 5px;
44 | }
45 |
46 | .mg-r5 {
47 | margin-right: 5px;
48 | }
49 |
50 | .mg-b5 {
51 | margin-bottom: 5px;
52 | }
53 |
54 | .mg-l5 {
55 | margin-left: 5px;
56 | }
57 |
58 | .mg-t10 {
59 | margin-top: 10px;
60 | }
61 |
62 | .mg-r10 {
63 | margin-right: 10px;
64 | }
65 |
66 | .mg-b10 {
67 | margin-bottom: 10px;
68 | }
69 |
70 | .mg-l10 {
71 | margin-left: 10px;
72 | }
73 |
74 | .mg-t15 {
75 | margin-top: 15px;
76 | }
77 |
78 | .mg-r15 {
79 | margin-right: 15px;
80 | }
81 |
82 | .mg-b15 {
83 | margin-bottom: 15px;
84 | }
85 |
86 | .mg-l15 {
87 | margin-left: 15px;
88 | }
89 |
90 | .mg-t20 {
91 | margin-top: 20px;
92 | }
93 |
94 | .mg-r20 {
95 | margin-right: 20px;
96 | }
97 |
98 | .mg-b20 {
99 | margin-bottom: 20px;
100 | }
101 |
102 | .mg-l20 {
103 | margin-left: 20px;
104 | }
105 |
106 | .pd5 {
107 | padding: 5px;
108 | }
109 |
110 | .pd10 {
111 | padding: 10px;
112 | }
113 |
114 | .pd15 {
115 | padding: 15px;
116 | }
117 |
118 | .pd20 {
119 | padding: 20px;
120 | }
121 |
122 | .pd-t0 {
123 | padding-top: 0;
124 | }
125 |
126 | .pd-r0 {
127 | padding-right: 0;
128 | }
129 |
130 | .pd-b0 {
131 | padding-bottom: 0;
132 | }
133 |
134 | .pd-l0 {
135 | padding-left: 0;
136 | }
137 |
138 | .pd-t5 {
139 | padding-top: 5px;
140 | }
141 |
142 | .pd-r5 {
143 | padding-right: 5px;
144 | }
145 |
146 | .pd-b5 {
147 | padding-bottom: 5px;
148 | }
149 |
150 | .pd-l5 {
151 | padding-left: 5px;
152 | }
153 |
154 | .pd-t10 {
155 | padding-top: 10px;
156 | }
157 |
158 | .pd-r10 {
159 | padding-right: 10px;
160 | }
161 |
162 | .pd-b10 {
163 | padding-bottom: 10px;
164 | }
165 |
166 | .pd-l10 {
167 | padding-left: 10px;
168 | }
169 |
170 | .pd-t15 {
171 | padding-top: 15px;
172 | }
173 |
174 | .pd-r15 {
175 | padding-right: 15px;
176 | }
177 |
178 | .pd-b15 {
179 | padding-bottom: 15px;
180 | }
181 |
182 | .pd-l15 {
183 | padding-left: 15px;
184 | }
185 |
186 | .pd-t20 {
187 | padding-top: 20px;
188 | }
189 |
190 | .pd-r20 {
191 | padding-right: 20px;
192 | }
193 |
194 | .pd-b20 {
195 | padding-bottom: 20px;
196 | }
197 |
198 | .pd-l20 {
199 | padding-left: 20px;
200 | }
201 |
202 | .fs12 {
203 | font-size: 12px;
204 | }
205 |
206 | .cred {
207 | color: red;
208 | }
209 |
210 | .pd-nav {
211 | padding-top: 46px;
212 | }
213 |
214 | .fade-enter-active, .fade-leave-active {
215 | transition: opacity 0.5s ease;
216 | }
217 |
218 | .fade-enter-from, .fade-leave-to {
219 | opacity: 0;
220 | }
--------------------------------------------------------------------------------
/src/views/TodoList.vue:
--------------------------------------------------------------------------------
1 |
2 |