bindaccount.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view :style="{marginTop:navH}"></view>
  6. <view class="home">
  7. <view class="card" v-if="!loading">
  8. <view class="head">
  9. <image :src="platform.platform_icon" mode=""></image>
  10. <span>{{platform.platform_name}}账号绑定</span>
  11. </view>
  12. <view class="body">
  13. <view>
  14. <uni-forms :modelValue="formData" ref="form" :rules="bindRules" validate-trigger="bind"
  15. err-show-type="undertext">
  16. <uni-forms-item name="name" required label="昵称">
  17. <uni-easyinput type="text" v-model="formData.platform_nickname" style="width:300rpx"
  18. placeholder="请填写账号昵称">
  19. </uni-easyinput>
  20. </uni-forms-item>
  21. <uni-forms-item name="numberfans" required label="粉丝数">
  22. <view class="number-inupt">
  23. <uni-easyinput type="number" v-model="fansCount" placeholder="可保留小数点后一位"
  24. v-if="fansCountInfo === 1" style="width:300rpx" @input="onInput1">
  25. </uni-easyinput>
  26. <uni-easyinput type="digit" v-model="fansCount" placeholder="可保留小数点后一位" v-else
  27. style="width:300rpx" @input="onInput">
  28. </uni-easyinput>
  29. <picker @change="bindPickerChange" :value="index" :range="fansRange"
  30. style="z-index: 999;background-color: #fcdf41;padding: 0 10rpx;border-radius: 5rpx;"
  31. range-key="label">
  32. <view>{{ fansLabel }}</view>
  33. </picker>
  34. </view>
  35. <!-- <view style="font-size: 24rpx;padding-left: 10px;" @click="hasClicked = true" v-else>
  36. <p>点选数字单位</p>
  37. </view> -->
  38. </uni-forms-item>
  39. <uni-forms-item name="home_link" required label=" " label-width='10'>
  40. <uni-easyinput class="home-link" type="text" v-model="formData.home_page_url"
  41. style="width:650rpx" placeholder="请填写个人主页链接">
  42. </uni-easyinput>
  43. </uni-forms-item>
  44. <view style="margin-top: 40rpx;">
  45. <uni-forms-item name="home_img" required label="主页截图">
  46. <htz-image-upload :max="1" mediaType="image" name="file" :chooseNum="1"
  47. v-model="imageData" @chooseSuccess="ceshiChooseSuccess">
  48. </htz-image-upload>
  49. </uni-forms-item>
  50. </view>
  51. </uni-forms>
  52. <view class="heng-line"></view>
  53. <button class="btn1" @click="submitForm('form')">
  54. 确认绑定</button>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import mvBar from "@/components/mys_navBar/mysNavBar";
  63. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  64. import getPolicyEncode from '@/components/obs/getPolicy.js';
  65. import getSignature from '@/components/obs/GetSignature.js';
  66. export default {
  67. components: {
  68. mvBar,
  69. htzImageUpload,
  70. },
  71. data() {
  72. return {
  73. navH: getApp().globalData.navHeight,
  74. hasClicked: false,
  75. loading: true,
  76. accountId: '',
  77. platform: {
  78. platform_id: '',
  79. platform_name: '',
  80. platform_icon: '',
  81. },
  82. isBind: true,
  83. imageData: [],
  84. formData: {
  85. platform_nickname: '',
  86. fans_count: '',
  87. home_page_url: '',
  88. home_page_capture_url: ''
  89. },
  90. index: 0,
  91. fansLabel: "选择单位",
  92. fansCount: null,
  93. fansCountInfo: 1,
  94. fansRange: [{
  95. value: 1,
  96. label: '个'
  97. },
  98. {
  99. value: 10000,
  100. label: '万'
  101. },
  102. {
  103. value: 100000000,
  104. label: '亿'
  105. }
  106. ],
  107. mysNavConfig: {
  108. /* 开启单页显示首页图标 */
  109. isHome: true,
  110. /* 固定导航 */
  111. navFixed: true,
  112. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  113. navTitle: {
  114. text: "社媒账号绑定",
  115. color: "",
  116. fontSize: "32rpx", // px upx rpx
  117. fontWeight: "normal", // 100 - 700
  118. },
  119. btnType: "type2",
  120. onLeftClick: '',
  121. /* type2 按钮 */
  122. type2Config: {
  123. // 左图标
  124. leftPath: "/static/img/png2.png",
  125. // 右图标
  126. rightPath: "/static/img/png4.png",
  127. // 圆角
  128. radius: "40rpx",
  129. },
  130. }, // 密码登录校验规则
  131. bindRules: {
  132. name: {
  133. rules: [{
  134. required: true,
  135. errorMessage: '请输入昵称'
  136. }]
  137. },
  138. home_img: {
  139. rules: [{
  140. required: true,
  141. errorMessage: '请上传主页截图',
  142. }]
  143. }
  144. },
  145. urlRegList: [
  146. /(.*)http(s?)\:\/\/((www\.)?)(xiaohongshu\.com)(.*)/,
  147. /(.*)http(s?)\:\/\/((www\.)?)((v\.)?)(douyin\.com)(.*)/,
  148. /(.*)http(s?)\:\/\/((www\.)?)((m\.)?)(weibo\.(com|cn))(.*)/,
  149. /(.*)http(s?)\:\/\/((www\.)?)((v|kpfshanghai)\.m\.chenzhongtech\.com)(.*)/,
  150. /(.*)http(s?)\:\/\/((www\.)?)(b23\.tv)(.*)/,
  151. /(.*)http(s?)\:\/\/((www\.)?)((m\.)?)(dianping\.(com|cn))(.*)/,
  152. /(.*)http(s?)\:\/\/((www\.)?)(zhihu\.com)(.*)/,
  153. ]
  154. }
  155. },
  156. onReady() {},
  157. async onShow() {},
  158. async onLoad(options) {
  159. this.platform.platform_id = parseInt(options.platform_id)
  160. if (options.account_id) {
  161. this.accountId = parseInt(options.account_id)
  162. this.isBind = false
  163. }
  164. this.loading = true;
  165. uni.showLoading({
  166. title: '加载中'
  167. });
  168. await this.getinfo();
  169. if (!this.isBind) {
  170. await this.getaccount()
  171. };
  172. this.loading = false;
  173. uni.hideLoading();
  174. },
  175. methods: {
  176. // 默认信息表,获取平台logo
  177. getinfo() {
  178. return this.$https.get('/youngee/c/g/get-info-tables')
  179. .then(res => {
  180. let list = res.data.data.ThirdPlatform
  181. for (var i = 0; i < list.length; ++i) {
  182. if (list[i].id == this.platform.platform_id) {
  183. this.platform.platform_icon = list[i].platform_icon
  184. this.platform.platform_name = list[i].platform_name
  185. }
  186. }
  187. })
  188. },
  189. getaccount() {
  190. return this.$https.get('/youngee/c/t/g/get-talent-account')
  191. .then(res => {
  192. console.log(res)
  193. if (res.data.code !== -3) {
  194. this.account = res.data.data
  195. this.imageData = []
  196. for (var i = 0; i < this.account.length; i++) {
  197. if (this.platform.platform_id == this.account[i].platform_id) {
  198. this.hasClicked = true
  199. this.formData.platform_nickname = this.account[i].platform_nickname
  200. this.formData.fans_count = this.account[i].fans_count
  201. this.formData.home_page_url = this.account[i].home_page_url
  202. this.imageData.push(this.account[i].home_page_capture_url);
  203. if (this.formData.fans_count >= 100000000) {
  204. this.index = 2
  205. this.fansCountInfo = this.fansRange[this.index].value;
  206. this.fansLabel = this.fansRange[this.index].label;
  207. this.fansCount = (this.formData.fans_count / 100000000).toFixed(1)
  208. } else if (this.formData.fans_count >= 10000) {
  209. this.index = 1
  210. this.fansCountInfo = this.fansRange[this.index].value;
  211. this.fansLabel = this.fansRange[this.index].label;
  212. this.fansCount = (this.formData.fans_count / 10000).toFixed(1)
  213. } else {
  214. this.index = 0
  215. this.fansCountInfo = this.fansRange[this.index].value;
  216. this.fansLabel = this.fansRange[this.index].label;
  217. this.fansCount = this.formData.fans_count
  218. }
  219. }
  220. }
  221. }
  222. })
  223. },
  224. /**
  225. * 手动提交
  226. * @param {Object} form
  227. */
  228. submitForm(form) {
  229. const urlReg = this.urlRegList[this.platform.platform_id - 1]
  230. if (!urlReg.test(this.formData.home_page_url)) {
  231. uni.showToast({
  232. title: '主页链接格式不正确',
  233. icon: 'none'
  234. })
  235. return
  236. }
  237. if (this.fansCount == null || this.fansCount * this.fansCountInfo <= 0 || this.fansLabel == "选择单位") {
  238. uni.showToast({
  239. title: '请填写粉丝量数量',
  240. icon: 'none'
  241. })
  242. return
  243. }
  244. this.formData.fans_count = this.fansCount * this.fansCountInfo
  245. if (this.imageData.length === 0) {
  246. uni.showToast({
  247. title: '请上传主页截图',
  248. icon: 'none'
  249. })
  250. return
  251. }
  252. let that = this
  253. that.$refs.form.validate()
  254. // that.$refs[form]
  255. // .submit()
  256. .then(res => {
  257. console.log('表单的值:', res)
  258. uni.showModal({
  259. title: '提示',
  260. content: '请保证账号信息的准确性和真实性',
  261. success: function(res) {
  262. if (res.confirm) {
  263. that.formData.home_page_capture_url = that.imageData[0]
  264. if (that.isBind) {
  265. that.$https.post('/youngee/c/t/p/add-talent-account', {
  266. platform_id: that.platform.platform_id,
  267. platform_nickname: that.formData.platform_nickname,
  268. home_page_url: that.formData.home_page_url,
  269. fans_count: that.formData.fans_count,
  270. home_page_capture_url: that.formData
  271. .home_page_capture_url,
  272. })
  273. .then(res => {
  274. console.log(res)
  275. if (res.data.code == 0) {
  276. uni.navigateBack()
  277. } else {
  278. let msg = res.data.msg
  279. uni.showToast({
  280. title: msg,
  281. icon: 'none',
  282. duration: 2000
  283. });
  284. }
  285. })
  286. } else {
  287. that.$https.post('/youngee/c/t/p/update-talent-account', {
  288. account_id: that.accountId,
  289. platform_id: that.platform.platform_id,
  290. platform_nickname: that.formData.platform_nickname,
  291. home_page_url: that.formData.home_page_url,
  292. fans_count: that.formData.fans_count,
  293. home_page_capture_url: that.formData
  294. .home_page_capture_url,
  295. })
  296. .then(res => {
  297. console.log(res)
  298. if (res.data.code == 0) {
  299. uni.navigateBack()
  300. } else {
  301. let msg = res.data.msg
  302. uni.showToast({
  303. title: msg,
  304. icon: 'none',
  305. duration: 2000
  306. });
  307. }
  308. })
  309. }
  310. } else if (res.cancel) {
  311. console.log('用户点击取消');
  312. }
  313. },
  314. });
  315. })
  316. .catch(errors => {
  317. console.error('验证失败:', errors)
  318. uni.showToast({
  319. title: '请填写账号昵称',
  320. icon: 'none'
  321. })
  322. })
  323. },
  324. exit() {
  325. uni.navigateBack()
  326. },
  327. // 粉丝量量级选择
  328. bindPickerChange: function(e) {
  329. if (this.index !== e.detail.value) {
  330. this.fansCount = null
  331. }
  332. this.index = e.detail.value;
  333. this.fansLabel = this.fansRange[this.index].label
  334. this.fansCountInfo = this.fansRange[this.index].value
  335. },
  336. ceshiChooseSuccess(tempFilePaths, e) { //选择图片返回
  337. console.log('ceshiChooseSuccess', tempFilePaths, e);
  338. if (e == 0) {
  339. this.store = 'talent_upload/' + this.guid() + '.png'
  340. // this.store = 'talent_upload/icon-edit2.png'
  341. // this.store = 'youngee/talent_upload/icon-edit.2png'
  342. } else if (e == 1) {
  343. this.store = 'talent_upload/' + this.guid() + '.mp4'
  344. }
  345. /****************
  346. 以下代码是自定义上传逻辑,仅供参考
  347. ***************/
  348. this.imgUpload(tempFilePaths);
  349. /*******************************/
  350. },
  351. imgUpload(tempFilePaths) {
  352. let that = this
  353. let config = {
  354. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  355. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  356. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  357. };
  358. let fileName = this.store; //指定上传到OBS桶中的对象名
  359. let OBSPolicy = { //设定policy内容
  360. "expiration": "2089-12-31T12:00:00.000Z",
  361. "conditions": [{
  362. "bucket": "horastar"
  363. }, //Bucket name
  364. // {"bucket": "goin"},
  365. {
  366. 'key': fileName
  367. }
  368. ]
  369. }
  370. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  371. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  372. uni.uploadFile({
  373. //url: config.EndPoint,
  374. url: config.EndPoint,
  375. filePath: tempFilePaths[0],
  376. name: 'file',
  377. formData: {
  378. 'AccessKeyID': config.AccessKeyId,
  379. 'policy': policyEncoded,
  380. 'signature': signature,
  381. 'key': fileName,
  382. },
  383. success: function(res) {
  384. console.log("res", res); //打印响应状态码
  385. if (res.statusCode == 204) {
  386. // that.imageData.push(config.EndPoint + '/' + fileName);
  387. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  388. that.imageData.push(obs_url)
  389. that.formData.home_page_capture_url = obs_url
  390. uni.showToast({
  391. title: '上传成功',
  392. icon: '成功'
  393. });
  394. } else {
  395. uni.showToast({
  396. title: '上传失败',
  397. icon: '失败'
  398. });
  399. }
  400. },
  401. fail: function(e) {
  402. console.log(e);
  403. uni.showToast({
  404. title: '上传失败22222',
  405. icon: '失败'
  406. });
  407. }
  408. })
  409. },
  410. guid() {
  411. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  412. var r = Math.random() * 16 | 0,
  413. v = c == 'x' ? r : (r & 0x3 | 0x8);
  414. return v.toString(16);
  415. });
  416. },
  417. onInput(e) {
  418. console.log(e)
  419. e = (e.match(/^\d*(\.?\d{0,1})/g)[0]) || null
  420. // //重新赋值给input
  421. if (e < 0 || e > 9999.9) {
  422. uni.showToast({
  423. title: '请输入[1,9999.9]区间内的数',
  424. icon: 'none'
  425. })
  426. console.log('请输入[1,9999.9]区间内的数')
  427. }
  428. this.$nextTick(() => {
  429. this.fansCount = (e > 0 && e <= 9999.9) ? e : null
  430. })
  431. },
  432. onInput1(e) {
  433. // 验证是否是纯数字
  434. const isNumber = /^\d*$/.test(e)
  435. // 过滤非数字
  436. e = e.replace(/\D/g, '')
  437. if (!isNumber || e < 0 || e > 9999) {
  438. uni.showToast({
  439. title: '请输入[0,9999]区间的整数',
  440. icon: 'none'
  441. })
  442. console.log('请输入[0,9999]区间的整数')
  443. }
  444. this.$nextTick(() => {
  445. this.fansCount = (e >= 0 && e <= 9999 && e.match(/^\d*/g)[0]) ? e : null
  446. })
  447. }
  448. },
  449. }
  450. </script>
  451. <style>
  452. .uni-easyinput__content-input {
  453. font-size: 24rpx !important;
  454. }
  455. /deep/.uni-forms-item__inner {
  456. border-bottom: none !important;
  457. margin-bottom: 0 !important;
  458. }
  459. .uni-forms-item__label {
  460. font-size: 30rpx;
  461. display: flex;
  462. flex-shrink: 0;
  463. box-sizing: border-box;
  464. flex-direction: row;
  465. align-items: center;
  466. width: 65px;
  467. padding: 5px 0;
  468. /* height: 36px; */
  469. }
  470. /deep/ .uni-forms-item__content {
  471. display: flex !important;
  472. align-items: center !important;
  473. /* justify-content: space-between; */
  474. }
  475. </style>
  476. <style lang="scss" scoped>
  477. .number-inupt {
  478. display: flex !important;
  479. align-items: center !important;
  480. }
  481. .card {
  482. padding: 24rpx;
  483. margin-top: 30rpx;
  484. border: 1rpx solid #F0D232;
  485. background-color: #ffffff;
  486. margin: 0 10rpx;
  487. }
  488. .head {
  489. padding-top: 5%;
  490. padding: 0 0 0 1%;
  491. height: 80rpx;
  492. margin-top: 2%;
  493. }
  494. .head span {
  495. color: #333333;
  496. font-size: 80%;
  497. font-weight: 550;
  498. text-indent: 2em;
  499. }
  500. .head image {
  501. vertical-align: middle;
  502. width: 50rpx;
  503. height: 50rpx;
  504. display: inline-block;
  505. padding-right: 14rpx;
  506. }
  507. .home-link {
  508. /deep/.uni-easyinput__content-input {
  509. background-color: #EBEBEB;
  510. border-radius: 15rpx;
  511. }
  512. }
  513. .heng-line {
  514. margin-top: 60rpx;
  515. margin-bottom: 50rpx;
  516. border-bottom: 1rpx solid #DCDCDC;
  517. }
  518. .signupbtn p {
  519. font-size: 30rpx;
  520. }
  521. .exit-btn {
  522. width: 200rpx;
  523. text-align: center;
  524. padding: 10rpx 30rpx;
  525. background-color: #C0C0C0;
  526. border: 0;
  527. border-radius: 10rpx;
  528. color: #FFFFFF;
  529. font-size: 30rpx;
  530. line-height: 180%;
  531. }
  532. .btn1 {
  533. margin: 30rpx;
  534. font-size: 35rpx;
  535. color: #000;
  536. background-color: #F0D232;
  537. border: none;
  538. border-radius: 0;
  539. }
  540. .uni-input-placeholder {
  541. font-size: 24rpx !important;
  542. }
  543. /deep/.uni-date-x--border {
  544. border: 0px solid #dcdfe6 !important;
  545. }
  546. /deep/.is-input-border {
  547. border: 0px solid #c8c7cc !important;
  548. }
  549. </style>