bindaccount.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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. }
  146. },
  147. onReady() {},
  148. async onShow() {},
  149. async onLoad(options) {
  150. this.platform.platform_id = parseInt(options.platform_id)
  151. if (options.account_id) {
  152. this.accountId = parseInt(options.account_id)
  153. this.isBind = false
  154. }
  155. this.loading = true;
  156. uni.showLoading({
  157. title: '加载中'
  158. });
  159. await this.getinfo();
  160. if (!this.isBind) {
  161. await this.getaccount()
  162. };
  163. this.loading = false;
  164. uni.hideLoading();
  165. },
  166. methods: {
  167. // 默认信息表,获取平台logo
  168. getinfo() {
  169. return this.$https.get('/youngee/c/g/get-info-tables')
  170. .then(res => {
  171. let list = res.data.data.ThirdPlatform
  172. for (var i = 0; i < list.length; ++i) {
  173. if (list[i].id == this.platform.platform_id) {
  174. this.platform.platform_icon = list[i].platform_icon
  175. this.platform.platform_name = list[i].platform_name
  176. }
  177. }
  178. })
  179. },
  180. getaccount() {
  181. return this.$https.get('/youngee/c/t/g/get-talent-account')
  182. .then(res => {
  183. console.log(res)
  184. if (res.data.code !== -3) {
  185. this.account = res.data.data
  186. this.imageData = []
  187. for (var i = 0; i < this.account.length; i++) {
  188. if (this.platform.platform_id == this.account[i].platform_id) {
  189. this.hasClicked = true
  190. this.formData.platform_nickname = this.account[i].platform_nickname
  191. this.formData.fans_count = this.account[i].fans_count
  192. this.formData.home_page_url = this.account[i].home_page_url
  193. this.imageData.push(this.account[i].home_page_capture_url);
  194. if (this.formData.fans_count >= 100000000) {
  195. this.index = 2
  196. this.fansCountInfo = this.fansRange[this.index].value;
  197. this.fansLabel = this.fansRange[this.index].label;
  198. this.fansCount = (this.formData.fans_count / 100000000).toFixed(1)
  199. } else if (this.formData.fans_count >= 10000) {
  200. this.index = 1
  201. this.fansCountInfo = this.fansRange[this.index].value;
  202. this.fansLabel = this.fansRange[this.index].label;
  203. this.fansCount = (this.formData.fans_count / 10000).toFixed(1)
  204. } else {
  205. this.index = 0
  206. this.fansCountInfo = this.fansRange[this.index].value;
  207. this.fansLabel = this.fansRange[this.index].label;
  208. this.fansCount = this.formData.fans_count
  209. }
  210. }
  211. }
  212. }
  213. })
  214. },
  215. /**
  216. * 手动提交
  217. * @param {Object} form
  218. */
  219. submitForm(form) {
  220. const urlReg =
  221. /(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%$#_]*)?/
  222. if (!urlReg.test(this.formData.home_page_url)) {
  223. uni.showToast({
  224. title: '主页链接格式不正确',
  225. icon: 'none'
  226. })
  227. return
  228. }
  229. if (this.fansCount == null || this.fansCount * this.fansCountInfo <= 0 || this.fansLabel == "选择单位") {
  230. uni.showToast({
  231. title: '请填写粉丝量数量',
  232. icon: 'none'
  233. })
  234. return
  235. }
  236. this.formData.fans_count = this.fansCount * this.fansCountInfo
  237. if (this.imageData.length === 0) {
  238. uni.showToast({
  239. title: '请上传主页截图',
  240. icon: 'none'
  241. })
  242. return
  243. }
  244. let that = this
  245. that.$refs.form.validate()
  246. // that.$refs[form]
  247. // .submit()
  248. .then(res => {
  249. console.log('表单的值:', res)
  250. uni.showModal({
  251. title: '提示',
  252. content: '请保证账号信息的准确性和真实性',
  253. success: function(res) {
  254. if (res.confirm) {
  255. that.formData.home_page_capture_url = that.imageData[0]
  256. if (that.isBind) {
  257. that.$https.post('/youngee/c/t/p/add-talent-account', {
  258. platform_id: that.platform.platform_id,
  259. platform_nickname: that.formData.platform_nickname,
  260. home_page_url: that.formData.home_page_url,
  261. fans_count: that.formData.fans_count,
  262. home_page_capture_url: that.formData
  263. .home_page_capture_url,
  264. })
  265. .then(res => {
  266. console.log(res)
  267. if (res.data.code == 0) {
  268. uni.navigateBack()
  269. } else {
  270. let msg = res.data.msg
  271. uni.showToast({
  272. title: msg,
  273. icon: 'none',
  274. duration: 2000
  275. });
  276. }
  277. })
  278. } else {
  279. that.$https.post('/youngee/c/t/p/update-talent-account', {
  280. account_id: that.accountId,
  281. platform_id: that.platform.platform_id,
  282. platform_nickname: that.formData.platform_nickname,
  283. home_page_url: that.formData.home_page_url,
  284. fans_count: that.formData.fans_count,
  285. home_page_capture_url: that.formData
  286. .home_page_capture_url,
  287. })
  288. .then(res => {
  289. console.log(res)
  290. if (res.data.code == 0) {
  291. uni.navigateBack()
  292. } else {
  293. let msg = res.data.msg
  294. uni.showToast({
  295. title: msg,
  296. icon: 'none',
  297. duration: 2000
  298. });
  299. }
  300. })
  301. }
  302. } else if (res.cancel) {
  303. console.log('用户点击取消');
  304. }
  305. },
  306. });
  307. })
  308. .catch(errors => {
  309. console.error('验证失败:', errors)
  310. uni.showToast({
  311. title: '请填写账号昵称',
  312. icon: 'none'
  313. })
  314. })
  315. },
  316. exit() {
  317. uni.navigateBack()
  318. },
  319. // 粉丝量量级选择
  320. bindPickerChange: function(e) {
  321. if (this.index !== e.detail.value) {
  322. this.fansCount = null
  323. }
  324. this.index = e.detail.value;
  325. this.fansLabel = this.fansRange[this.index].label
  326. this.fansCountInfo = this.fansRange[this.index].value
  327. },
  328. ceshiChooseSuccess(tempFilePaths, e) { //选择图片返回
  329. console.log('ceshiChooseSuccess', tempFilePaths, e);
  330. if (e == 0) {
  331. this.store = 'talent_upload/' + this.guid() + '.png'
  332. // this.store = 'talent_upload/guanwang.png'
  333. } else if (e == 1) {
  334. this.store = 'talent_upload/' + this.guid() + '.mp4'
  335. }
  336. /****************
  337. 以下代码是自定义上传逻辑,仅供参考
  338. ***************/
  339. this.imgUpload(tempFilePaths);
  340. /*******************************/
  341. },
  342. imgUpload(tempFilePaths) {
  343. let that = this
  344. let config = {
  345. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  346. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  347. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  348. };
  349. let fileName = this.store; //指定上传到OBS桶中的对象名
  350. let OBSPolicy = { //设定policy内容
  351. "expiration": "2089-12-31T12:00:00.000Z",
  352. "conditions": [{
  353. "bucket": "horastar"
  354. }, //Bucket name
  355. // {"bucket": "goin"},
  356. {
  357. 'key': fileName
  358. }
  359. ]
  360. }
  361. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  362. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  363. uni.uploadFile({
  364. //url: config.EndPoint,
  365. url: config.EndPoint,
  366. filePath: tempFilePaths[0],
  367. name: 'file',
  368. formData: {
  369. 'AccessKeyID': config.AccessKeyId,
  370. 'policy': policyEncoded,
  371. 'signature': signature,
  372. 'key': fileName,
  373. },
  374. success: function(res) {
  375. console.log("res", res); //打印响应状态码
  376. if (res.statusCode == 204) {
  377. // that.imageData.push(config.EndPoint + '/' + fileName);
  378. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  379. that.imageData.push(obs_url)
  380. that.formData.home_page_capture_url = obs_url
  381. uni.showToast({
  382. title: '上传成功',
  383. icon: '成功'
  384. });
  385. } else {
  386. uni.showToast({
  387. title: '上传失败',
  388. icon: '失败'
  389. });
  390. }
  391. },
  392. fail: function(e) {
  393. console.log(e);
  394. uni.showToast({
  395. title: '上传失败22222',
  396. icon: '失败'
  397. });
  398. }
  399. })
  400. },
  401. guid() {
  402. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  403. var r = Math.random() * 16 | 0,
  404. v = c == 'x' ? r : (r & 0x3 | 0x8);
  405. return v.toString(16);
  406. });
  407. },
  408. onInput(e) {
  409. console.log(e)
  410. e = (e.match(/^\d*(\.?\d{0,1})/g)[0]) || null
  411. // //重新赋值给input
  412. if (e < 0 || e > 9999.9) {
  413. uni.showToast({
  414. title: '请输入[1,9999.9]区间内的数',
  415. icon: 'none'
  416. })
  417. console.log('请输入[1,9999.9]区间内的数')
  418. }
  419. this.$nextTick(() => {
  420. this.fansCount = (e > 0 && e <= 9999.9) ? e : null
  421. })
  422. },
  423. onInput1(e) {
  424. // 验证是否是纯数字
  425. const isNumber = /^\d*$/.test(e)
  426. // 过滤非数字
  427. e = e.replace(/\D/g, '')
  428. if (!isNumber || e < 0 || e > 9999) {
  429. uni.showToast({
  430. title: '请输入[0,9999]区间的整数',
  431. icon: 'none'
  432. })
  433. console.log('请输入[0,9999]区间的整数')
  434. }
  435. this.$nextTick(() => {
  436. this.fansCount = (e >= 0 && e <= 9999 && e.match(/^\d*/g)[0]) ? e : null
  437. })
  438. }
  439. },
  440. }
  441. </script>
  442. <style>
  443. .uni-easyinput__content-input {
  444. font-size: 24rpx !important;
  445. }
  446. /deep/.uni-forms-item__inner {
  447. border-bottom: none !important;
  448. margin-bottom: 0 !important;
  449. }
  450. .uni-forms-item__label {
  451. font-size: 30rpx;
  452. display: flex;
  453. flex-shrink: 0;
  454. box-sizing: border-box;
  455. flex-direction: row;
  456. align-items: center;
  457. width: 65px;
  458. padding: 5px 0;
  459. /* height: 36px; */
  460. }
  461. /deep/ .uni-forms-item__content {
  462. display: flex !important;
  463. align-items: center !important;
  464. /* justify-content: space-between; */
  465. }
  466. </style>
  467. <style lang="scss" scoped>
  468. .number-inupt {
  469. display: flex !important;
  470. align-items: center !important;
  471. }
  472. .card {
  473. padding: 24rpx;
  474. margin-top: 30rpx;
  475. border: 1rpx solid #F0D232;
  476. background-color: #ffffff;
  477. margin: 0 10rpx;
  478. }
  479. .head {
  480. padding-top: 5%;
  481. padding: 0 0 0 1%;
  482. height: 80rpx;
  483. margin-top: 2%;
  484. }
  485. .head span {
  486. color: #333333;
  487. font-size: 80%;
  488. font-weight: 550;
  489. text-indent: 2em;
  490. }
  491. .head image {
  492. vertical-align: middle;
  493. width: 50rpx;
  494. height: 50rpx;
  495. display: inline-block;
  496. padding-right: 14rpx;
  497. }
  498. .home-link {
  499. /deep/.uni-easyinput__content-input {
  500. background-color: #EBEBEB;
  501. border-radius: 15rpx;
  502. }
  503. }
  504. .heng-line {
  505. margin-top: 60rpx;
  506. margin-bottom: 50rpx;
  507. border-bottom: 1rpx solid #DCDCDC;
  508. }
  509. .signupbtn p {
  510. font-size: 30rpx;
  511. }
  512. .exit-btn {
  513. width: 200rpx;
  514. text-align: center;
  515. padding: 10rpx 30rpx;
  516. background-color: #C0C0C0;
  517. border: 0;
  518. border-radius: 10rpx;
  519. color: #FFFFFF;
  520. font-size: 30rpx;
  521. line-height: 180%;
  522. }
  523. .btn1 {
  524. margin: 30rpx;
  525. font-size: 35rpx;
  526. color: #000;
  527. background-color: #F0D232;
  528. border: none;
  529. border-radius: 0;
  530. }
  531. .uni-input-placeholder {
  532. font-size: 24rpx !important;
  533. }
  534. /deep/.uni-date-x--border {
  535. border: 0px solid #dcdfe6 !important;
  536. }
  537. /deep/.is-input-border {
  538. border: 0px solid #c8c7cc !important;
  539. }
  540. </style>