yq-avatar.vue 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  1. <template name="yq-avatar">
  2. <view>
  3. <image :src="imgSrc.imgSrc" @click="fSelect" :style="[ iS ]" class="my-avatar"></image>
  4. <canvas canvas-id="avatar-canvas" id="avatar-canvas" class="my-canvas" :style="{top: sT, height: csH}"
  5. disable-scroll="false"></canvas>
  6. <canvas canvas-id="oper-canvas" id="oper-canvas" class="oper-canvas" :style="{top: sT, height: csH}"
  7. disable-scroll="false" @touchstart="fStart" @touchmove="fMove" @touchend="fEnd"></canvas>
  8. <canvas canvas-id="prv-canvas" id="prv-canvas" class="prv-canvas" disable-scroll="false"
  9. @touchstart="fHideImg" :style="{ height: csH, top: pT }"></canvas>
  10. <view class="oper-wrapper" :style="{display: sD, top:tp}">
  11. <view class="oper">
  12. <view class="btn-wrapper" v-if="sO">
  13. <view @click="fSelect" hover-class="hover" :style="{width: bW}"><text>重选</text></view>
  14. <view @click="fClose" hover-class="hover" :style="{width: bW}"><text>关闭</text></view>
  15. <view @click="fRotate" hover-class="hover" :style="{width: bW, display: bD}"><text>旋转</text></view>
  16. <view @click="fPreview" hover-class="hover" :style="{width: bW}"><text>预览</text></view>
  17. <view @click="fUpload" hover-class="hover" :style="{width: bW}"><text>上传</text></view>
  18. </view>
  19. <view class="clr-wrapper" v-else>
  20. <slider class="my-slider" @change="fColorChange" block-size="25" value="0" min="-100" max="100" activeColor="red"
  21. backgroundColor="green" block-color="grey" show-value></slider>
  22. <view @click="fPrvUpload" hover-class="hover" :style="{width: bW}"><text>上传</text></view>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. // +----------------------------------------------------------------------
  30. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  31. // +----------------------------------------------------------------------
  32. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  33. // +----------------------------------------------------------------------
  34. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  35. // +----------------------------------------------------------------------
  36. // | Author: CRMEB Team <admin@crmeb.com>
  37. // +----------------------------------------------------------------------
  38. "use strict";
  39. const tH = 50;
  40. export default {
  41. name: "yq-avatar",
  42. data() {
  43. return {
  44. csH: '0px',
  45. sD: 'none',
  46. sT: '-10000px',
  47. pT: '-10000px',
  48. iS: {},
  49. sS: {},
  50. sO: true,
  51. bW: '19%',
  52. bD: 'flex',
  53. tp: 0,
  54. imgSrc: {
  55. imgSrc: ''
  56. }
  57. };
  58. },
  59. watch: {
  60. avatarSrc() {
  61. this.imgSrc.imgSrc = this.avatarSrc;
  62. }
  63. },
  64. props: {
  65. avatarSrc: '',
  66. avatarStyle: '',
  67. selWidth: '',
  68. selHeight: '',
  69. expWidth: '',
  70. expHeight: '',
  71. minScale: '',
  72. maxScale: '',
  73. canScale: '',
  74. canRotate: '',
  75. lockWidth: '',
  76. lockHeight: '',
  77. stretch: '',
  78. lock: '',
  79. fileType: '',
  80. noTab: '',
  81. inner: '',
  82. quality: '',
  83. index: '',
  84. bgImage: '',
  85. },
  86. created() {
  87. this.cc = uni.createCanvasContext('avatar-canvas', this);
  88. this.cco = uni.createCanvasContext('oper-canvas', this);
  89. this.ccp = uni.createCanvasContext('prv-canvas', this);
  90. this.qlty = parseFloat(this.quality) || 1;
  91. this.imgSrc.imgSrc = this.avatarSrc;
  92. this.letRotate = (this.canRotate === false || this.inner === true || this.inner === 'true' || this.canRotate === 'false') ? 0 : 1;
  93. this.letScale = (this.canScale === false || this.canScale === 'false') ? 0 : 1;
  94. this.isin = (this.inner === true || this.inner === 'true') ? 1 : 0;
  95. this.indx = this.index || undefined;
  96. this.mnScale = parseFloat(this.minScale) || 0.3;
  97. this.mxScale = parseFloat(this.maxScale) || 4;
  98. this.noBar = (this.noTab === true || this.noTab === 'true') ? 1 : 0;
  99. this.stc = this.stretch;
  100. this.lck = this.lock;
  101. this.fType = this.fileType === 'jpg' ? 'jpg' : 'png';
  102. if (this.isin||!this.letRotate) {
  103. this.bW = '24%';
  104. this.bD = 'none';
  105. } else {
  106. this.bW = '19%';
  107. this.bD = 'flex';
  108. }
  109. if (this.noBar) {
  110. this.fWindowResize();
  111. } else {
  112. uni.showTabBar({
  113. fail: ()=>{
  114. this.noBar = 1;
  115. },
  116. success: ()=>{
  117. this.noBar = 0;
  118. },
  119. complete: (res) => {
  120. this.fWindowResize();
  121. }
  122. });
  123. }
  124. },
  125. methods: {
  126. fWindowResize() {
  127. let sysInfo = uni.getSystemInfoSync();
  128. this.platform = sysInfo.platform;
  129. this.wW = sysInfo.windowWidth;
  130. // #ifdef H5
  131. this.drawTop = sysInfo.windowTop;
  132. // #endif
  133. // #ifndef H5
  134. this.drawTop = 0;
  135. // #endif
  136. // #ifdef MP-ALIPAY
  137. this.wH = sysInfo.screenHeight - sysInfo.statusBarHeight - sysInfo.titleBarHeight;
  138. this.csH = this.wH - tH + 'px';
  139. // #endif
  140. // #ifndef MP-ALIPAY
  141. this.wH = sysInfo.windowHeight;
  142. if(!this.noBar) this.wH += tH;
  143. this.csH = this.wH - tH + 'px';
  144. // #endif
  145. this.tp = this.csH;
  146. // #ifdef H5
  147. this.tp = sysInfo.windowTop + parseInt(this.csH)+ 'px';
  148. // #endif
  149. this.pxRatio = this.wW / 750;
  150. let style = this.avatarStyle;
  151. if (style && style !== true && (style = style.trim())) {
  152. style = style.split(';');
  153. let obj = {};
  154. for (let v of style) {
  155. if (!v) continue;
  156. v = v.trim().split(':');
  157. if (v[1].toString().indexOf('upx') >= 0) {
  158. let arr = v[1].trim().split(' ');
  159. for (let k in arr) {
  160. if (!arr[k]) continue;
  161. if (arr[k].toString().indexOf('upx') >= 0) {
  162. arr[k] = parseFloat(arr[k]) * this.pxRatio + 'px';
  163. }
  164. }
  165. v[1] = arr.join(' ');
  166. }
  167. obj[v[0].trim()] = v[1].trim();
  168. }
  169. this.iS = obj;
  170. }
  171. this.expWidth && (this.eW = this.expWidth.toString().indexOf('upx') >= 0 ? parseInt(this.expWidth) * this.pxRatio :
  172. parseInt(this.expWidth));
  173. this.expHeight && (this.eH = this.expHeight.toString().indexOf('upx') >= 0 ? parseInt(this.expHeight) * this.pxRatio :
  174. parseInt(this.expHeight));
  175. if (this.sD === 'flex') {
  176. this.fDrawInit(true);
  177. }
  178. this.fHideImg();
  179. },
  180. fSelect() {
  181. if (this.fSelecting) return;
  182. this.fSelecting = true;
  183. setTimeout(() => {
  184. this.fSelecting = false;
  185. }, 500);
  186. uni.chooseImage({
  187. count: 1,
  188. sizeType: ['original', 'compressed'],
  189. sourceType: ['album', 'camera'],
  190. success: (r) => {
  191. // #ifdef MP-ALIPAY
  192. uni.showLoading();
  193. // #endif
  194. // #ifndef MP-ALIPAY
  195. uni.showLoading({
  196. title: '加载中...',
  197. mask: true
  198. });
  199. // #endif
  200. let path = this.imgPath = r.tempFilePaths[0];
  201. let name = r.tempFiles[0].name;
  202. if(!name && path) {
  203. name = path.split('/');
  204. name = name[name.length - 1];
  205. }
  206. uni.getImageInfo({
  207. src: path,
  208. success: r => {
  209. this.imgWidth = r.width;
  210. this.imgHeight = r.height;
  211. this.path = path;
  212. if (!this.hasSel) {
  213. let style = this.sS || {};
  214. if (this.selWidth && this.selHeight) {
  215. let sW = this.selWidth.toString().indexOf('upx') >= 0 ? parseInt(this.selWidth) * this.pxRatio : parseInt(
  216. this.selWidth),
  217. sH = this.selHeight.toString().indexOf('upx') >= 0 ? parseInt(this.selHeight) * this.pxRatio : parseInt(
  218. this.selHeight);
  219. style.width = sW + 'px';
  220. style.height = sH + 'px';
  221. style.top = ((this.wH - sH - tH)|0) / 2 + 'px';
  222. style.left = ((this.wW - sW)|0) / 2 + 'px';
  223. } else {
  224. uni.showModal({
  225. title: '裁剪框的宽或高没有设置',
  226. showCancel: false
  227. })
  228. return;
  229. }
  230. this.sS = style;
  231. }
  232. if (this.noBar) {
  233. this.fDrawInit(true);
  234. } else {
  235. uni.hideTabBar({
  236. complete: () => {
  237. this.fDrawInit(true);
  238. }
  239. });
  240. }
  241. this.$emit('getName',name);
  242. },
  243. fail: () => {
  244. uni.showToast({
  245. title: "请选择正确图片",
  246. duration: 2000,
  247. })
  248. },
  249. complete() {
  250. uni.hideLoading();
  251. }
  252. });
  253. }
  254. })
  255. },
  256. fUpload() {
  257. if (this.fUploading) return;
  258. this.fUploading = true;
  259. setTimeout(() => {
  260. this.fUploading = false;
  261. }, 1000)
  262. let style = this.sS,
  263. x = parseInt(style.left),
  264. y = parseInt(style.top),
  265. width = parseInt(style.width),
  266. height = parseInt(style.height),
  267. expWidth = this.eW || (width* this.pixelRatio),
  268. expHeight = this.eH || (height* this.pixelRatio);
  269. // #ifdef MP-ALIPAY
  270. uni.showLoading();
  271. // #endif
  272. // #ifndef MP-ALIPAY
  273. uni.showLoading({
  274. title: '加载中...',
  275. mask: true
  276. });
  277. // #endif
  278. this.sD = 'none';
  279. this.sT = '-10000px';
  280. this.hasSel = false;
  281. this.fHideImg();
  282. // #ifdef MP-ALIPAY
  283. this.cc.toTempFilePath({
  284. x: x,
  285. y: y,
  286. width: width,
  287. height: height,
  288. destWidth: expWidth,
  289. destHeight: expHeight,
  290. fileType: this.fType,
  291. quality: this.qlty,
  292. success: (r) => {
  293. r = r.apFilePath;
  294. this.$emit("upload", {
  295. avatar: this.imgSrc,
  296. path: r,
  297. index: this.indx,
  298. data: this.rtn,
  299. base64: this.base64 || null
  300. });
  301. },
  302. fail: (res) => {
  303. uni.showToast({
  304. title: "error1",
  305. duration: 2000,
  306. })
  307. },
  308. complete: () => {
  309. uni.hideLoading();
  310. this.noBar || uni.showTabBar();
  311. this.$emit("end");
  312. }
  313. });
  314. // #endif
  315. // #ifndef MP-ALIPAY
  316. uni.canvasToTempFilePath({
  317. x: x,
  318. y: y,
  319. width: width,
  320. height: height,
  321. destWidth: expWidth,
  322. destHeight: expHeight,
  323. canvasId: 'avatar-canvas',
  324. fileType: this.fType,
  325. quality: this.qlty,
  326. success: (r) => {
  327. r = r.tempFilePath;
  328. // #ifdef H5
  329. this.btop(r).then((r) => {
  330. this.$emit("upload", {
  331. avatar: this.imgSrc,
  332. path: r,
  333. index: this.indx,
  334. data: this.rtn,
  335. base64: this.base64 || null
  336. });
  337. return;
  338. })
  339. // #endif
  340. // #ifndef H5
  341. this.$emit("upload", {
  342. avatar: this.imgSrc,
  343. path: r,
  344. index: this.indx,
  345. data: this.rtn,
  346. base64: this.base64 || null
  347. });
  348. // #endif
  349. },
  350. fail: (res) => {
  351. uni.showToast({
  352. title: "error1",
  353. duration: 2000,
  354. })
  355. },
  356. complete: () => {
  357. uni.hideLoading();
  358. this.noBar || uni.showTabBar();
  359. this.$emit("end");
  360. }
  361. }, this);
  362. // #endif
  363. },
  364. fPrvUpload() {
  365. if (this.fPrvUploading) return;
  366. this.fPrvUploading = true;
  367. setTimeout(() => {
  368. this.fPrvUploading = false;
  369. }, 1000)
  370. let style = this.sS,
  371. destWidth = parseInt(style.width),
  372. destHeight = parseInt(style.height),
  373. prvX = this.prvX,
  374. prvY = this.prvY,
  375. prvWidth = this.prvWidth,
  376. prvHeight = this.prvHeight,
  377. expWidth = this.eW || (parseInt(style.width) * this.pixelRatio),
  378. expHeight = this.eH || (parseInt(style.height) * this.pixelRatio);
  379. // #ifdef MP-ALIPAY
  380. uni.showLoading();
  381. // #endif
  382. // #ifndef MP-ALIPAY
  383. uni.showLoading({
  384. title: '加载中...',
  385. mask: true
  386. });
  387. // #endif
  388. this.sD = 'none';
  389. this.sT = '-10000px';
  390. this.hasSel = false;
  391. this.fHideImg();
  392. // #ifdef MP-ALIPAY
  393. this.ccp.toTempFilePath({
  394. x: prvX,
  395. y: prvY,
  396. width: prvWidth,
  397. height: prvHeight,
  398. destWidth: expWidth,
  399. destHeight: expHeight,
  400. fileType: this.fType,
  401. quality: this.qlty,
  402. success: (r) => {
  403. r = r.apFilePath;
  404. this.$emit("upload", {
  405. avatar: this.imgSrc,
  406. path: r,
  407. index: this.indx,
  408. data: this.rtn,
  409. base64: this.base64 || null
  410. });
  411. },
  412. fail: () => {
  413. uni.showToast({
  414. title: "error_prv",
  415. duration: 2000,
  416. })
  417. },
  418. complete: () => {
  419. uni.hideLoading();
  420. this.noBar || uni.showTabBar();
  421. this.$emit("end");
  422. }
  423. });
  424. // #endif
  425. // #ifndef MP-ALIPAY
  426. uni.canvasToTempFilePath({
  427. x: prvX,
  428. y: prvY,
  429. width: prvWidth,
  430. height: prvHeight,
  431. destWidth: expWidth,
  432. destHeight: expHeight,
  433. canvasId: 'prv-canvas',
  434. fileType: this.fType,
  435. quality: this.qlty,
  436. success: (r) => {
  437. r = r.tempFilePath;
  438. // #ifdef H5
  439. this.btop(r).then((r) => {
  440. this.$emit("upload", {
  441. avatar: this.imgSrc,
  442. path: r,
  443. index: this.indx,
  444. data: this.rtn,
  445. base64: this.base64 || null
  446. });
  447. })
  448. // #endif
  449. // #ifndef H5
  450. this.$emit("upload", {
  451. avatar: this.imgSrc,
  452. path: r,
  453. index: this.indx,
  454. data: this.rtn,
  455. base64: this.base64 || null
  456. });
  457. // #endif
  458. },
  459. fail: () => {
  460. uni.showToast({
  461. title: "error_prv",
  462. duration: 2000,
  463. })
  464. },
  465. complete: () => {
  466. uni.hideLoading();
  467. this.noBar || uni.showTabBar();
  468. this.$emit("end");
  469. }
  470. }, this);
  471. // #endif
  472. },
  473. fDrawInit(ini = false) {
  474. let allWidth = this.wW,
  475. allHeight = this.wH,
  476. imgWidth = this.imgWidth,
  477. imgHeight = this.imgHeight,
  478. imgRadio = imgWidth / imgHeight,
  479. useWidth = allWidth - 40,
  480. useHeight = allHeight - tH - 80,
  481. useRadio = useWidth / useHeight,
  482. sW = parseInt(this.sS.width),
  483. sH = parseInt(this.sS.height);
  484. this.fixWidth = 0;
  485. this.fixHeight = 0;
  486. this.lckWidth = 0;
  487. this.lckHeight = 0;
  488. switch (this.stc) {
  489. case 'x':
  490. this.fixWidth = 1;
  491. break;
  492. case 'y':
  493. this.fixHeight = 1;
  494. break;
  495. case 'long':
  496. if (imgRadio > 1) this.fixWidth = 1;
  497. else this.fixHeight = 1;
  498. break;
  499. case 'short':
  500. if (imgRadio > 1) this.fixHeight = 1;
  501. else this.fixWidth = 1;
  502. break;
  503. case 'longSel':
  504. if (sW > sH) this.fixWidth = 1;
  505. else this.fixHeight = 1;
  506. break;
  507. case 'shortSel':
  508. if (sW > sH) this.fixHeight = 1;
  509. else this.fixWidth = 1;
  510. break;
  511. }
  512. switch (this.lck) {
  513. case 'x':
  514. this.lckWidth = 1;
  515. break;
  516. case 'y':
  517. this.lckHeight = 1;
  518. break;
  519. case 'long':
  520. if (imgRadio > 1) this.lckWidth = 1;
  521. else this.lckHeight = 1;
  522. break;
  523. case 'short':
  524. if (imgRadio > 1) this.lckHeight = 1;
  525. else this.lckWidth = 1;
  526. break;
  527. case 'longSel':
  528. if (sW > sH) this.lckWidth = 1;
  529. else this.lckHeight = 1;
  530. break;
  531. case 'shortSel':
  532. if (sW > sH) this.lckHeight = 1;
  533. else this.lckWidth = 1;
  534. break;
  535. }
  536. if (this.fixWidth) {
  537. useWidth = sW;
  538. useHeight = useWidth / imgRadio;
  539. } else if (this.fixHeight) {
  540. useHeight = sH;
  541. useWidth = useHeight * imgRadio;
  542. } else if (imgRadio < useRadio) {
  543. if (imgHeight < useHeight) {
  544. useWidth = imgWidth;
  545. useHeight = imgHeight;
  546. } else {
  547. useWidth = useHeight * imgRadio;
  548. }
  549. } else {
  550. if (imgWidth < useWidth) {
  551. useWidth = imgWidth;
  552. useHeight = imgHeight;
  553. } else {
  554. useHeight = useWidth / imgRadio;
  555. }
  556. }
  557. if (this.isin) {
  558. if (useWidth < sW) {
  559. useWidth = sW;
  560. useHeight = useWidth / imgRadio;
  561. this.lckHeight = 0;
  562. }
  563. if (useHeight < sH) {
  564. useHeight = sH;
  565. useWidth = useHeight * imgRadio;
  566. this.lckWidth = 0;
  567. }
  568. }
  569. this.scaleSize = 1;
  570. this.rotateDeg = 0;
  571. this.posWidth = (allWidth - useWidth) / 2 | 0;
  572. this.posHeight = (allHeight - useHeight - tH) / 2 | 0;
  573. this.useWidth = useWidth | 0;
  574. this.useHeight = useHeight | 0;
  575. this.centerX = this.posWidth + useWidth / 2;
  576. this.centerY = this.posHeight + useHeight / 2;
  577. this.focusX = 0;
  578. this.focusY = 0;
  579. let style = this.sS,
  580. left = parseInt(style.left),
  581. top = parseInt(style.top),
  582. width = parseInt(style.width),
  583. height = parseInt(style.height),
  584. canvas = this.canvas,
  585. canvasOper = this.canvasOper,
  586. cc = this.cc,
  587. cco = this.cco;
  588. cco.beginPath();
  589. cco.setLineWidth(3);
  590. cco.setGlobalAlpha(1);
  591. cco.setStrokeStyle('white');
  592. cco.strokeRect(left, top, width, height);
  593. cco.setFillStyle('black');
  594. cco.setGlobalAlpha(0.5);
  595. cco.fillRect(0, 0, this.wW, top);
  596. cco.fillRect(0, top, left, height);
  597. cco.fillRect(0, top + height, this.wW, this.wH - height - top - tH);
  598. cco.fillRect(left + width, top, this.wW - width - left, height);
  599. cco.setGlobalAlpha(1);
  600. cco.setStrokeStyle('red');
  601. cco.moveTo(left+15, top);
  602. cco.lineTo(left, top);
  603. cco.lineTo(left, top+15);
  604. cco.moveTo(left+width-15, top);
  605. cco.lineTo(left+width, top);
  606. cco.lineTo(left+width, top+15);
  607. cco.moveTo(left+15, top+height);
  608. cco.lineTo(left, top+height);
  609. cco.lineTo(left, top+height-15);
  610. cco.moveTo(left+width-15, top+height);
  611. cco.lineTo(left+width, top+height);
  612. cco.lineTo(left+width, top+height-15);
  613. cco.stroke();
  614. cco.draw(false, () => {
  615. if (ini) {
  616. this.sD = 'flex';
  617. this.sT = this.drawTop + 'px';
  618. this.fDrawImage(true);
  619. }
  620. });
  621. this.$emit("init");
  622. },
  623. fDrawImage(ini = false) {
  624. let tm_now = Date.now();
  625. if (tm_now - this.drawTm < 20) return;
  626. this.drawTm = tm_now;
  627. let cc = this.cc,
  628. imgWidth = this.useWidth * this.scaleSize,
  629. imgHeight = this.useHeight * this.scaleSize;
  630. // #ifdef MP-ALIPAY
  631. cc.save();
  632. // #endif
  633. if (this.bgImage) {
  634. // #ifdef MP-ALIPAY
  635. cc.clearRect(0, 0, this.wW, this.wH - tH);
  636. // #endif
  637. // #ifndef MP-ALIPAY
  638. cc.drawImage(this.bgImage, 0, 0, this.wW, this.wH - tH);
  639. // #endif
  640. } else {
  641. cc.fillRect(0, 0, this.wW, this.wH - tH);
  642. }
  643. if (this.isin) {
  644. let cx = this.focusX * (this.scaleSize - 1),
  645. cy = this.focusY * (this.scaleSize - 1);
  646. cc.translate(this.centerX, this.centerY);
  647. cc.rotate(this.rotateDeg * Math.PI / 180);
  648. cc.drawImage(this.imgPath, this.posWidth-this.centerX-cx, this.posHeight-this.centerY-cy, imgWidth, imgHeight);
  649. } else {
  650. cc.translate(this.posWidth + imgWidth / 2, this.posHeight + imgHeight / 2);
  651. cc.rotate(this.rotateDeg * Math.PI / 180);
  652. cc.drawImage(this.imgPath, -imgWidth / 2, -imgHeight / 2, imgWidth, imgHeight);
  653. }
  654. cc.draw(false);
  655. // #ifdef MP-ALIPAY
  656. cc.restore();
  657. // #endif
  658. },
  659. fPreview() {
  660. if (this.fPreviewing) return;
  661. this.fPreviewing = true;
  662. setTimeout(() => {
  663. this.fPreviewing = false;
  664. }, 1000);
  665. let style = this.sS,
  666. x = parseInt(style.left),
  667. y = parseInt(style.top),
  668. width = parseInt(style.width),
  669. height = parseInt(style.height);
  670. // #ifdef MP-ALIPAY
  671. uni.showLoading();
  672. // #endif
  673. // #ifndef MP-ALIPAY
  674. uni.showLoading({
  675. title: '加载中...',
  676. mask: true
  677. });
  678. // #endif
  679. // #ifdef MP-ALIPAY
  680. this.cc.toTempFilePath({
  681. x: x,
  682. y: y,
  683. width: width,
  684. height: height,
  685. expWidth: width * this.pixelRatio,
  686. expHeight: height * this.pixelRatio,
  687. fileType: this.fType,
  688. quality: this.qlty,
  689. success: (r) => {
  690. this.prvImgTmp = r = r.apFilePath;
  691. let ccp = this.ccp,
  692. prvX = this.wW,
  693. prvY = parseInt(this.csH),
  694. prvWidth = parseInt(this.sS.width),
  695. prvHeight = parseInt(this.sS.height),
  696. useWidth = prvX - 40,
  697. useHeight = prvY - 80,
  698. radio = useWidth / prvWidth,
  699. rHeight = prvHeight * radio;
  700. if (rHeight < useHeight) {
  701. prvWidth = useWidth;
  702. prvHeight = rHeight;
  703. } else {
  704. radio = useHeight / prvHeight;
  705. prvWidth *= radio;
  706. prvHeight = useHeight;
  707. }
  708. ccp.fillRect(0, 0, prvX, prvY);
  709. this.prvX = prvX = ((prvX - prvWidth) / 2) | 0;
  710. this.prvY = prvY = ((prvY - prvHeight) / 2) | 0;
  711. this.prvWidth = prvWidth = prvWidth | 0;
  712. this.prvHeight = prvHeight = prvHeight | 0;
  713. ccp.drawImage(r, prvX, prvY, prvWidth, prvHeight);
  714. ccp.draw(false);
  715. this.sO = false;
  716. this.pT = '0';
  717. },
  718. fail: () => {
  719. uni.showToast({
  720. title: "error2",
  721. duration: 2000,
  722. })
  723. },
  724. complete: () => {
  725. uni.hideLoading();
  726. }
  727. });
  728. // #endif
  729. // #ifndef MP-ALIPAY
  730. uni.canvasToTempFilePath({
  731. x: x,
  732. y: y,
  733. width: width,
  734. height: height,
  735. expWidth: width * this.pixelRatio,
  736. expHeight: height * this.pixelRatio,
  737. canvasId: 'avatar-canvas',
  738. fileType: this.fType,
  739. quality: this.qlty,
  740. success: (r) => {
  741. this.prvImgTmp = r = r.tempFilePath;
  742. let ccp = this.ccp,
  743. prvX = this.wW,
  744. prvY = parseInt(this.csH);
  745. // #ifndef H5||MP-WEIXIN||APP-PLUS
  746. prvY += tH;
  747. // #endif
  748. // #ifdef APP-PLUS
  749. if (this.platform === 'android') {
  750. prvY += tH;
  751. }
  752. // #endif
  753. let prvWidth = parseInt(this.sS.width),
  754. prvHeight = parseInt(this.sS.height),
  755. useWidth = prvX - 40,
  756. useHeight = prvY - 80,
  757. radio = useWidth / prvWidth,
  758. rHeight = prvHeight * radio;
  759. if (rHeight < useHeight) {
  760. prvWidth = useWidth;
  761. prvHeight = rHeight;
  762. } else {
  763. radio = useHeight / prvHeight;
  764. prvWidth *= radio;
  765. prvHeight = useHeight;
  766. }
  767. ccp.fillRect(0, 0, prvX, prvY);
  768. this.prvX = prvX = ((prvX - prvWidth) / 2) | 0;
  769. this.prvY = prvY = ((prvY - prvHeight) / 2) | 0;
  770. this.prvWidth = prvWidth = prvWidth | 0;
  771. this.prvHeight = prvHeight = prvHeight | 0;
  772. ccp.drawImage(r, prvX, prvY, prvWidth, prvHeight);
  773. ccp.draw(false);
  774. // #ifdef H5
  775. this.btop(r).then((r) => {
  776. this.sO = false;
  777. this.pT = this.drawTop + 'px';
  778. })
  779. // #endif
  780. this.sO = false;
  781. // if (this.platform === 'android') this.sO = false;
  782. this.pT = this.drawTop + 'px';
  783. },
  784. fail: () => {
  785. uni.showToast({
  786. title: "error2",
  787. duration: 2000,
  788. })
  789. },
  790. complete: () => {
  791. uni.hideLoading();
  792. }
  793. }, this);
  794. // #endif
  795. },
  796. fChooseImg(index = undefined, params = undefined, data = undefined) {
  797. if (params) {
  798. let sW = params.selWidth,
  799. sH = params.selHeight,
  800. expWidth = params.expWidth,
  801. expHeight = params.expHeight,
  802. quality = params.quality,
  803. canRotate = params.canRotate,
  804. canScale = params.canScale,
  805. minScale = params.minScale,
  806. maxScale = params.maxScale,
  807. stretch = params.stretch,
  808. fileType = params.fileType,
  809. inner = params.inner,
  810. lock = params.lock;
  811. expWidth && (this.eW = expWidth.toString().indexOf('upx') >= 0 ? parseInt(expWidth) * this.pxRatio : parseInt(
  812. expWidth));
  813. expHeight && (this.eH = expHeight.toString().indexOf('upx') >= 0 ? parseInt(expHeight) * this.pxRatio : parseInt(
  814. expHeight));
  815. this.letRotate = (canRotate === false || inner === true || inner === 'true' || canRotate === 'false') ? 0 : 1;
  816. this.letScale = (canScale === false || canScale === 'false') ? 0 : 1;
  817. this.qlty = parseFloat(quality) || 1;
  818. this.mnScale = parseFloat(minScale) || 0.3;
  819. this.mxScale = parseFloat(maxScale) || 4;
  820. this.stc = stretch;
  821. this.isin = (inner === true || inner === 'true') ? 1 : 0;
  822. this.fType = fileType === 'jpg' ? 'jpg' : 'png';
  823. this.lck = lock;
  824. if (this.isin||!this.letRotate) {
  825. this.bW = '24%';
  826. this.bD = 'none';
  827. } else {
  828. this.bW = '19%';
  829. this.bD = 'flex';
  830. }
  831. if (sW && sH) {
  832. sW = sW.toString().indexOf('upx') >= 0 ? parseInt(sW) * this.pxRatio : parseInt(sW);
  833. sH = sH.toString().indexOf('upx') >= 0 ? parseInt(sH) * this.pxRatio : parseInt(sH);
  834. this.sS.width = sW + 'px';
  835. this.sS.height = sH + 'px';
  836. this.sS.top = ((this.wH - sH - tH)|0) / 2 + 'px';
  837. this.sS.left = ((this.wW - sW)|0) / 2 + 'px';
  838. this.hasSel = true;
  839. }
  840. }
  841. this.rtn = data;
  842. this.indx = index;
  843. this.fSelect();
  844. },
  845. fRotate() {
  846. this.rotateDeg += 90 - this.rotateDeg % 90;
  847. this.fDrawImage();
  848. },
  849. fStart(e) {
  850. let touches = e.touches,
  851. touch0 = touches[0],
  852. touch1 = touches[1];
  853. this.touch0 = touch0;
  854. this.touch1 = touch1;
  855. if (touch1) {
  856. let x = touch1.x - touch0.x,
  857. y = touch1.y - touch0.y;
  858. this.fgDistance = Math.sqrt(x * x + y * y);
  859. }
  860. },
  861. fMove(e) {
  862. let touches = e.touches,
  863. touch0 = touches[0],
  864. touch1 = touches[1];
  865. if (touch1) {
  866. let x = touch1.x - touch0.x,
  867. y = touch1.y - touch0.y,
  868. fgDistance = Math.sqrt(x * x + y * y),
  869. scaleSize = 0.005 * (fgDistance - this.fgDistance),
  870. beScaleSize = this.scaleSize + scaleSize;
  871. do {
  872. if (!this.letScale) break;
  873. if (beScaleSize < this.mnScale) break;
  874. if (beScaleSize > this.mxScale) break;
  875. let growX = this.useWidth * scaleSize / 2,
  876. growY = this.useHeight * scaleSize / 2;
  877. if (this.isin) {
  878. let imgWidth = this.useWidth * beScaleSize,
  879. imgHeight = this.useHeight * beScaleSize,
  880. l = this.posWidth - growX,
  881. t = this.posHeight - growY,
  882. r = l + imgWidth,
  883. b = t + imgHeight,
  884. left = parseInt(this.sS.left),
  885. top = parseInt(this.sS.top),
  886. width = parseInt(this.sS.width),
  887. height = parseInt(this.sS.height),
  888. right = left + width,
  889. bottom = top + height,
  890. cx, cy;
  891. if (imgWidth <= width || imgHeight <= height) break;
  892. this.cx = cx = this.focusX * beScaleSize - this.focusX,
  893. this.cy = cy = this.focusY * beScaleSize - this.focusY;
  894. this.posWidth -= growX;
  895. this.posHeight -= growY;
  896. if (this.posWidth - cx > left) {
  897. this.posWidth = left + cx;
  898. }
  899. if (this.posWidth + imgWidth - cx < right) {
  900. this.posWidth = right - imgWidth + cx;
  901. }
  902. if (this.posHeight - cy > top) {
  903. this.posHeight = top + cy;
  904. }
  905. if (this.posHeight + imgHeight - cy < bottom) {
  906. this.posHeight = bottom - imgHeight + cy;
  907. }
  908. } else {
  909. this.posWidth -= growX;
  910. this.posHeight -= growY;
  911. }
  912. this.scaleSize = beScaleSize;
  913. } while (0);
  914. this.fgDistance = fgDistance;
  915. if (touch1.x !== touch0.x && this.letRotate) {
  916. x = (this.touch1.y - this.touch0.y) / (this.touch1.x - this.touch0.x);
  917. y = (touch1.y - touch0.y) / (touch1.x - touch0.x);
  918. this.rotateDeg += Math.atan((y - x) / (1 + x * y)) * 180 / Math.PI;
  919. this.touch0 = touch0;
  920. this.touch1 = touch1;
  921. }
  922. this.fDrawImage();
  923. } else if (this.touch0) {
  924. let x = touch0.x - this.touch0.x,
  925. y = touch0.y - this.touch0.y,
  926. beX = this.posWidth + x,
  927. beY = this.posHeight + y;
  928. if (this.isin) {
  929. let imgWidth = this.useWidth * this.scaleSize,
  930. imgHeight = this.useHeight * this.scaleSize,
  931. l = beX,
  932. t = beY,
  933. r = l + imgWidth,
  934. b = t + imgHeight,
  935. left = parseInt(this.sS.left),
  936. top = parseInt(this.sS.top),
  937. right = left + parseInt(this.sS.width),
  938. bottom = top + parseInt(this.sS.height),
  939. cx, cy;
  940. this.cx = cx = this.focusX * this.scaleSize - this.focusX;
  941. this.cy = cy = this.focusY * this.scaleSize - this.focusY;
  942. if (!this.lckWidth && Math.abs(x) < 100) {
  943. if (left < l - cx) {
  944. this.posWidth = left + cx;
  945. } else if (right > r - cx) {
  946. this.posWidth = right - imgWidth + cx;
  947. } else {
  948. this.posWidth = beX;
  949. this.focusX -= x;
  950. }
  951. }
  952. if (!this.lckHeight && Math.abs(y) < 100) {
  953. if (top < t - cy) {
  954. this.focusY -= (top + cy - this.posHeight);
  955. this.posHeight = top + cy;
  956. } else if (bottom > b - cy) {
  957. this.focusY -= (bottom + cy - (this.posHeight + imgHeight));
  958. this.posHeight = bottom - imgHeight + cy;
  959. } else {
  960. this.posHeight = beY;
  961. this.focusY -= y;
  962. }
  963. }
  964. } else {
  965. if (Math.abs(x) < 100 && !this.lckWidth) this.posWidth = beX;
  966. if (Math.abs(y) < 100 && !this.lckHeight) this.posHeight = beY;
  967. this.focusX -= x;
  968. this.focusY -= y;
  969. }
  970. this.touch0 = touch0;
  971. this.fDrawImage();
  972. }
  973. },
  974. fEnd(e) {
  975. let touches = e.touches,
  976. touch0 = touches && touches[0],
  977. touch1 = touches && touches[1];
  978. if (touch0) {
  979. this.touch0 = touch0;
  980. } else {
  981. this.touch0 = null;
  982. this.touch1 = null;
  983. }
  984. },
  985. fHideImg() {
  986. this.prvImg = '';
  987. this.pT = '-10000px';
  988. this.sO = true;
  989. this.prvImgData = null;
  990. this.target = null;
  991. },
  992. fClose() {
  993. this.sD = 'none';
  994. this.sT = '-10000px';
  995. this.hasSel = false;
  996. this.fHideImg();
  997. this.noBar || uni.showTabBar();
  998. this.$emit("end");
  999. },
  1000. fGetImgData() {
  1001. return new Promise((resolve, reject) => {
  1002. let prvX = this.prvX,
  1003. prvY = this.prvY,
  1004. prvWidth = this.prvWidth,
  1005. prvHeight = this.prvHeight;
  1006. // #ifdef MP-ALIPAY
  1007. this.ccp.getImageData({
  1008. x: prvX,
  1009. y: prvY,
  1010. width: prvWidth,
  1011. height: prvHeight,
  1012. success(res) {
  1013. resolve(res.data);
  1014. },
  1015. fail(err) {
  1016. reject(err);
  1017. }
  1018. }, this);
  1019. // #endif
  1020. // #ifndef MP-ALIPAY
  1021. uni.canvasGetImageData({
  1022. canvasId: 'prv-canvas',
  1023. x: prvX,
  1024. y: prvY,
  1025. width: prvWidth,
  1026. height: prvHeight,
  1027. success(res) {
  1028. resolve(res.data);
  1029. },
  1030. fail(err) {
  1031. reject(err);
  1032. }
  1033. }, this);
  1034. // #endif
  1035. });
  1036. },
  1037. async fColorChange(e) {
  1038. let tm_now = Date.now();
  1039. if (tm_now - this.prvTm < 100) return;
  1040. this.prvTm = tm_now;
  1041. // #ifdef MP-ALIPAY
  1042. uni.showLoading();
  1043. // #endif
  1044. // #ifndef MP-ALIPAY
  1045. uni.showLoading({
  1046. title: '加载中...',
  1047. mask: true
  1048. });
  1049. // #endif
  1050. if (!this.prvImgData) {
  1051. if (!(this.prvImgData = await this.fGetImgData().catch(() => {
  1052. uni.showToast({
  1053. title: "error_read",
  1054. duration: 2000,
  1055. })
  1056. }))) return;
  1057. this.target = new Uint8ClampedArray(this.prvImgData.length);
  1058. }
  1059. let data = this.prvImgData,
  1060. target = this.target,
  1061. i = e.detail.value,
  1062. r, g, b, a, h, s, l, d, p, q, t, min, max, hK, tR, tG, tB;
  1063. if (i === 0) {
  1064. target = data;
  1065. } else {
  1066. i = (i + 100) / 200;
  1067. if (i < 0.005) i = 0;
  1068. if (i > 0.995) i = 1;
  1069. for (let n = data.length - 1; n >= 0; n -= 4) {
  1070. r = data[n - 3] / 255;
  1071. g = data[n - 2] / 255;
  1072. b = data[n - 1] / 255;
  1073. max = Math.max(r, g, b);
  1074. min = Math.min(r, g, b);
  1075. d = max - min;
  1076. if (max === min) {
  1077. h = 0;
  1078. } else if (max === r && g >= b) {
  1079. h = 60 * ((g - b) / d);
  1080. } else if (max === r && g < b) {
  1081. h = 60 * ((g - b) / d) + 360;
  1082. } else if (max === g) {
  1083. h = 60 * ((b - r) / d) + 120;
  1084. } else if (max === b) {
  1085. h = 60 * ((r - g) / d) + 240;
  1086. }
  1087. l = (max + min) / 2;
  1088. if (l === 0 || max === min) {
  1089. s = 0;
  1090. } else if (0 < l && l <= 0.5) {
  1091. s = d / (2 * l);
  1092. } else if (l > 0.5) {
  1093. s = d / (2 - 2 * l);
  1094. }
  1095. data[n] && (a = data[n]);
  1096. if (i < 0.5) {
  1097. s = s * i / 0.5;
  1098. } else if (i > 0.5) {
  1099. s = 2 * s + 2 * i - (s * i / 0.5) - 1;
  1100. }
  1101. if (s === 0) {
  1102. r = g = b = Math.round(l * 255);
  1103. } else {
  1104. if (l < 0.5) {
  1105. q = l * (1 + s);
  1106. } else if (l >= 0.5) {
  1107. q = l + s - (l * s);
  1108. }
  1109. p = 2 * l - q;
  1110. hK = h / 360;
  1111. tR = hK + 1 / 3;
  1112. tG = hK;
  1113. tB = hK - 1 / 3;
  1114. let correctRGB = (t) => {
  1115. if (t < 0) {
  1116. return t + 1.0;
  1117. }
  1118. if (t > 1) {
  1119. return t - 1.0;
  1120. }
  1121. return t;
  1122. };
  1123. let createRGB = (t) => {
  1124. if (t < (1 / 6)) {
  1125. return p + ((q - p) * 6 * t);
  1126. } else if (t >= (1 / 6) && t < (1 / 2)) {
  1127. return q;
  1128. } else if (t >= (1 / 2) && t < (2 / 3)) {
  1129. return p + ((q - p) * 6 * ((2 / 3) - t));
  1130. }
  1131. return p;
  1132. };
  1133. r = tR = Math.round(createRGB(correctRGB(tR)) * 255);
  1134. g = tG = Math.round(createRGB(correctRGB(tG)) * 255);
  1135. b = tB = Math.round(createRGB(correctRGB(tB)) * 255);
  1136. }
  1137. a && (target[n] = a);
  1138. target[n - 3] = r;
  1139. target[n - 2] = g;
  1140. target[n - 1] = b;
  1141. }
  1142. }
  1143. let prvX = this.prvX,
  1144. prvY = this.prvY,
  1145. prvWidth = this.prvWidth,
  1146. prvHeight = this.prvHeight;
  1147. // #ifdef MP-ALIPAY
  1148. this.ccp.putImageData({
  1149. x: prvX,
  1150. y: prvY,
  1151. width: prvWidth,
  1152. height: prvHeight,
  1153. data: target,
  1154. fail() {
  1155. uni.showToast({
  1156. title: 'error_put',
  1157. duration: 2000
  1158. })
  1159. },
  1160. complete() {
  1161. uni.hideLoading();
  1162. }
  1163. }, this);
  1164. // #endif
  1165. // #ifndef MP-ALIPAY
  1166. uni.canvasPutImageData({
  1167. canvasId: 'prv-canvas',
  1168. x: prvX,
  1169. y: prvY,
  1170. width: prvWidth,
  1171. height: prvHeight,
  1172. data: target,
  1173. fail() {
  1174. uni.showToast({
  1175. title: 'error_put',
  1176. duration: 2000
  1177. })
  1178. },
  1179. complete() {
  1180. uni.hideLoading();
  1181. }
  1182. }, this);
  1183. // #endif
  1184. },
  1185. btop(base64) {
  1186. this.base64 = base64;
  1187. return new Promise(function(resolve, reject) {
  1188. var arr = base64.split(','),
  1189. mime = arr[0].match(/:(.*?);/)[1],
  1190. bstr = atob(arr[1]),
  1191. n = bstr.length,
  1192. u8arr = new Uint8Array(n);
  1193. while (n--) {
  1194. u8arr[n] = bstr.charCodeAt(n);
  1195. }
  1196. return resolve((window.URL || window.webkitURL).createObjectURL(new Blob([u8arr], {
  1197. type: mime
  1198. })));
  1199. });
  1200. },
  1201. }
  1202. }
  1203. </script>
  1204. <style scoped>
  1205. .my-canvas {
  1206. display: flex;
  1207. position: fixed !important;
  1208. background: #000000;
  1209. left: 0;
  1210. z-index: 100000;
  1211. width: 100%;
  1212. }
  1213. .my-avatar {
  1214. width: 150upx;
  1215. height: 150upx;
  1216. border-radius: 100%;
  1217. }
  1218. .oper-canvas {
  1219. display: flex;
  1220. position: fixed !important;
  1221. left: 0;
  1222. z-index: 100001;
  1223. width: 100%;
  1224. }
  1225. .prv-canvas {
  1226. display: flex;
  1227. position: fixed !important;
  1228. background: #000000;
  1229. left: 0;
  1230. z-index: 200000;
  1231. width: 100%;
  1232. }
  1233. .oper-wrapper {
  1234. height: 50px;
  1235. position: fixed !important;
  1236. box-sizing: border-box;
  1237. border: 1px solid #F1F1F1;
  1238. background: #ffffff;
  1239. width: 100%;
  1240. left: 0;
  1241. bottom: 0;
  1242. z-index: 100009;
  1243. flex-direction: row;
  1244. }
  1245. .oper {
  1246. display: flex;
  1247. flex-direction: column;
  1248. justify-content: center;
  1249. padding: 10upx 20upx;
  1250. width: 100%;
  1251. height: 100%;
  1252. box-sizing: border-box;
  1253. align-self: center;
  1254. }
  1255. .btn-wrapper {
  1256. display: flex;
  1257. flex-direction: row;
  1258. /* #ifndef H5 */
  1259. flex-grow: 1;
  1260. /* #endif */
  1261. /* #ifdef H5 */
  1262. height: 50px;
  1263. /* #endif */
  1264. justify-content: space-between;
  1265. }
  1266. .btn-wrapper view {
  1267. display: flex;
  1268. align-items: center;
  1269. justify-content: center;
  1270. font-size: 16px;
  1271. color: #333;
  1272. border: 1px solid #f1f1f1;
  1273. border-radius: 6%;
  1274. }
  1275. .hover {
  1276. background: #f1f1f1;
  1277. border-radius: 6%;
  1278. }
  1279. .clr-wrapper {
  1280. display: flex;
  1281. flex-direction: row;
  1282. flex-grow: 1;
  1283. }
  1284. .clr-wrapper view {
  1285. display: flex;
  1286. align-items: center;
  1287. justify-content: center;
  1288. font-size: 16px;
  1289. color: #333;
  1290. border: 1px solid #f1f1f1;
  1291. border-radius: 6%;
  1292. }
  1293. .my-slider {
  1294. flex-grow: 1;
  1295. }
  1296. </style>