bindaccount.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view class="home">
  6. <view class="card" v-if="!loading">
  7. <view class="head">
  8. <image :src="platform.platform_icon" mode=""></image>
  9. <span>{{platform.platform_name}}账号绑定</span>
  10. </view>
  11. <view class="body">
  12. <view>
  13. <uni-forms :modelValue="formData" ref="form" validate-trigger="bind" err-show-type="undertext">
  14. <uni-forms-item name="name" required label="昵称">
  15. <uni-easyinput type="text" v-model="formData.platform_nickname" placeholder="请填写账号昵称">
  16. </uni-easyinput>
  17. </uni-forms-item>
  18. <uni-forms-item name="numberfans" required label="粉丝数">
  19. <uni-easyinput type="number" v-model="formData.fans_count" placeholder="请填写粉丝数量">
  20. </uni-easyinput>
  21. </uni-forms-item>
  22. <uni-forms-item name="home_link" required label=" " label-width='10'>
  23. <uni-easyinput class="home-link" type="text" v-model="formData.home_page_url"
  24. placeholder="请填写个人主页链接">
  25. </uni-easyinput>
  26. </uni-forms-item>
  27. <view style="margin-top: 40rpx;">
  28. <uni-forms-item name="home_img" required label="主页截图">
  29. <htz-image-upload :max="1" mediaType="image" name="file" :chooseNum="1"
  30. v-model="imageData" @chooseSuccess="ceshiChooseSuccess">
  31. </htz-image-upload>
  32. </uni-forms-item>
  33. </view>
  34. </uni-forms>
  35. <view class="heng-line"></view>
  36. <button class="btn1" @click="submitForm('form')">
  37. 确认绑定</button>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import mvBar from "@/components/mys_navBar/mysNavBar";
  46. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  47. import getPolicyEncode from '@/components/obs/getPolicy.js';
  48. import getSignature from '@/components/obs/GetSignature.js';
  49. export default {
  50. components: {
  51. mvBar,
  52. htzImageUpload,
  53. },
  54. data() {
  55. return {
  56. loading: true,
  57. accountId: '',
  58. platform: {
  59. platform_id: '',
  60. platform_name: '',
  61. platform_icon: '',
  62. },
  63. isBind: true,
  64. imageData: [],
  65. formData: {
  66. platform_nickname: '',
  67. fans_count: '',
  68. home_page_url: '',
  69. },
  70. mysNavConfig: {
  71. /* 开启单页显示首页图标 */
  72. isHome: true,
  73. /* 固定导航 */
  74. navFixed: true,
  75. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  76. navTitle: {
  77. text: "社媒账号绑定",
  78. color: "",
  79. fontSize: "32rpx", // px upx rpx
  80. fontWeight: "normal", // 100 - 700
  81. },
  82. btnType: "type2",
  83. onLeftClick: '',
  84. /* type2 按钮 */
  85. type2Config: {
  86. // 左图标
  87. leftPath: "/static/img/png2.png",
  88. // 右图标
  89. rightPath: "/static/img/png4.png",
  90. // 圆角
  91. radius: "40rpx",
  92. },
  93. },
  94. }
  95. },
  96. onReady() {},
  97. async onShow() {
  98. this.loading = true;
  99. uni.showLoading({
  100. title: '加载中'
  101. });
  102. await this.getinfo();
  103. if (!this.isBind) {
  104. await this.getaccount()
  105. };
  106. this.loading = false;
  107. uni.hideLoading();
  108. },
  109. onLoad() {},
  110. onLoad(options) {
  111. this.platform.platform_id = parseInt(options.platform_id)
  112. if (options.account_id) {
  113. this.accountId = parseInt(options.account_id)
  114. this.isBind = false
  115. }
  116. },
  117. methods: {
  118. // 默认信息表,获取平台logo
  119. getinfo() {
  120. return this.$https.get('/youngee/c/g/get-info-tables')
  121. .then(res => {
  122. let list = res.data.data.ThirdPlatform
  123. for (var i = 0; i < list.length; ++i) {
  124. if (list[i].id == this.platform.platform_id) {
  125. this.platform.platform_icon = list[i].platform_icon
  126. this.platform.platform_name = list[i].platform_name
  127. }
  128. }
  129. })
  130. },
  131. getaccount() {
  132. return this.$https.get('/youngee/c/t/g/get-talent-account')
  133. .then(res => {
  134. console.log(res)
  135. if (res.data.code !== -3) {
  136. this.account = res.data.data
  137. this.imageData = []
  138. for (var i = 0; i < this.account.length; i++) {
  139. if (this.platform.platform_id == this.account[i].platform_id) {
  140. this.formData.platform_nickname = this.account[i].platform_nickname
  141. this.formData.fans_count = this.account[i].fans_count
  142. this.formData.home_page_url = this.account[i].home_page_url
  143. this.imageData.push(this.account[i].home_page_capture_url);
  144. }
  145. }
  146. }
  147. })
  148. },
  149. /**
  150. * 手动提交
  151. * @param {Object} form
  152. */
  153. submitForm(form) {
  154. const urlReg =
  155. /(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%$#_]*)?/
  156. if (!urlReg.test(this.formData.home_page_url)) {
  157. uni.showToast({
  158. title: '主页链接格式不正确',
  159. icon: 'none'
  160. })
  161. return
  162. }
  163. let that = this
  164. uni.showModal({
  165. title: '提示',
  166. content: '请保证账号信息的准确性和真实性',
  167. success: function(res) {
  168. if (res.confirm) {
  169. that.$refs[form]
  170. .submit()
  171. .then(res => {
  172. console.log('表单的值:', res)
  173. that.formData.home_page_capture_url = that.imageData[0]
  174. if (that.isBind) {
  175. that.$https.post('/youngee/c/t/p/add-talent-account', {
  176. platform_id: that.platform.platform_id,
  177. platform_nickname: that.formData.platform_nickname,
  178. home_page_url: that.formData.home_page_url,
  179. fans_count: that.formData.fans_count,
  180. home_page_capture_url: that.formData
  181. .home_page_capture_url,
  182. })
  183. .then(res => {
  184. console.log(res)
  185. if (res.data.code == 0) {
  186. uni.navigateBack()
  187. } else {
  188. let msg = res.data.msg
  189. uni.showToast({
  190. title: msg,
  191. icon: 'none',
  192. duration: 2000
  193. });
  194. }
  195. })
  196. } else {
  197. that.$https.post('/youngee/c/t/p/update-talent-account', {
  198. account_id: that.accountId,
  199. platform_id: that.platform.platform_id,
  200. platform_nickname: that.formData.platform_nickname,
  201. home_page_url: that.formData.home_page_url,
  202. fans_count: that.formData.fans_count,
  203. home_page_capture_url: that.formData
  204. .home_page_capture_url,
  205. })
  206. .then(res => {
  207. console.log(res)
  208. if (res.data.code == 0) {
  209. uni.navigateBack()
  210. } else {
  211. let msg = res.data.msg
  212. uni.showToast({
  213. title: msg,
  214. icon: 'none',
  215. duration: 2000
  216. });
  217. }
  218. })
  219. }
  220. })
  221. .catch(errors => {
  222. console.error('验证失败:', errors)
  223. uni.showToast({
  224. title: '请填写所有信息',
  225. icon: 'none'
  226. })
  227. })
  228. } else if (res.cancel) {
  229. console.log('用户点击取消');
  230. }
  231. }
  232. });
  233. },
  234. exit() {
  235. uni.navigateBack()
  236. },
  237. ceshiChooseSuccess(tempFilePaths, e) { //选择图片返回
  238. console.log('ceshiChooseSuccess', tempFilePaths, e);
  239. if (e == 0) {
  240. this.store = 'talent_upload/' + this.guid() + '.png'
  241. // this.store = 'talent_upload/icon-warning.png'
  242. } else if (e == 1) {
  243. this.store = 'talent_upload/' + this.guid() + '.mp4'
  244. }
  245. /****************
  246. 以下代码是自定义上传逻辑,仅供参考
  247. ***************/
  248. this.imgUpload(tempFilePaths);
  249. /*******************************/
  250. console.log("imgdata" + this.imageData)
  251. },
  252. imgUpload(tempFilePaths) {
  253. let that = this
  254. console.log('imgUpload', tempFilePaths)
  255. let config = {
  256. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  257. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  258. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  259. };
  260. let fileName = this.store; //指定上传到OBS桶中的对象名
  261. let OBSPolicy = { //设定policy内容
  262. "expiration": "2089-12-31T12:00:00.000Z",
  263. "conditions": [{
  264. "bucket": "horastar"
  265. }, //Bucket name
  266. // {"bucket": "goin"},
  267. {
  268. 'key': fileName
  269. }
  270. ]
  271. }
  272. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  273. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  274. uni.uploadFile({
  275. //url: config.EndPoint,
  276. url: config.EndPoint,
  277. filePath: tempFilePaths[0],
  278. name: 'file',
  279. formData: {
  280. 'AccessKeyID': config.AccessKeyId,
  281. 'policy': policyEncoded,
  282. 'signature': signature,
  283. 'key': fileName,
  284. },
  285. success: function(res) {
  286. console.log(res.statusCode); //打印响应状态码
  287. if (res.statusCode == '204') {
  288. that.imageData.push(config.EndPoint + '/' + fileName);
  289. console.log('上传图片成功', res)
  290. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  291. console.log(obs_url)
  292. that.formData.home_img = obs_url
  293. uni.showToast({
  294. title: '上传成功',
  295. icon: '成功'
  296. });
  297. } else {
  298. console.log('上传图片失败', res)
  299. uni.showToast({
  300. title: '上传失败',
  301. icon: '失败'
  302. });
  303. }
  304. },
  305. fail: function(e) {
  306. console.log(e);
  307. uni.showToast({
  308. title: '上传失败22222',
  309. icon: '失败'
  310. });
  311. }
  312. })
  313. },
  314. guid() {
  315. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  316. var r = Math.random() * 16 | 0,
  317. v = c == 'x' ? r : (r & 0x3 | 0x8);
  318. return v.toString(16);
  319. });
  320. },
  321. },
  322. }
  323. </script>
  324. <style>
  325. .uni-easyinput__content-input {
  326. font-size: 24rpx !important;
  327. }
  328. /deep/.uni-forms-item__inner {
  329. border-bottom: none !important;
  330. margin-bottom: 0 !important;
  331. }
  332. .uni-forms-item__label {
  333. font-size: 30rpx;
  334. display: flex;
  335. flex-shrink: 0;
  336. box-sizing: border-box;
  337. flex-direction: row;
  338. align-items: center;
  339. width: 65px;
  340. padding: 5px 0;
  341. /* height: 36px; */
  342. }
  343. </style>
  344. <style lang="scss" scoped>
  345. .card {
  346. padding: 24rpx;
  347. margin-top: 30rpx;
  348. border: 1rpx solid #F0D232;
  349. background-color: #ffffff;
  350. margin: 0 10rpx;
  351. }
  352. .head {
  353. padding-top: 5%;
  354. padding: 0 0 0 1%;
  355. height: 80rpx;
  356. margin-top: 2%;
  357. }
  358. .head span {
  359. color: #333333;
  360. font-size: 80%;
  361. font-weight: 550;
  362. text-indent: 2em;
  363. }
  364. .head image {
  365. vertical-align: middle;
  366. width: 50rpx;
  367. height: 50rpx;
  368. display: inline-block;
  369. padding-right: 14rpx;
  370. }
  371. .home-link {
  372. /deep/.uni-easyinput__content-input {
  373. background-color: #EBEBEB;
  374. border-radius: 15rpx;
  375. }
  376. }
  377. .heng-line {
  378. margin-top: 60rpx;
  379. margin-bottom: 50rpx;
  380. border-bottom: 1rpx solid #DCDCDC;
  381. }
  382. .signupbtn p {
  383. font-size: 30rpx;
  384. }
  385. .exit-btn {
  386. width: 200rpx;
  387. text-align: center;
  388. padding: 10rpx 30rpx;
  389. background-color: #C0C0C0;
  390. border: 0;
  391. border-radius: 10rpx;
  392. color: #FFFFFF;
  393. font-size: 30rpx;
  394. line-height: 180%;
  395. }
  396. .btn1 {
  397. margin: 30rpx;
  398. font-size: 35rpx;
  399. color: #000;
  400. background-color: #F0D232;
  401. border: none;
  402. border-radius: 0;
  403. }
  404. .uni-input-placeholder {
  405. font-size: 24rpx !important;
  406. }
  407. /deep/.uni-date-x--border {
  408. border: 0px solid #dcdfe6 !important;
  409. }
  410. /deep/.is-input-border {
  411. border: 0px solid #c8c7cc !important;
  412. }
  413. </style>