bindaccount.vue 12 KB

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