upload.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view :style="{marginTop:navH}"></view>
  6. <view>
  7. <view style="margin: 40rpx;font-size: 32rpx">
  8. <p style="margin-bottom: 20rpx;">上传链接</p>
  9. <textarea v-model="link_url" style="height: 50px;width: 100%;"
  10. placeholder="请上传正确链接~" />
  11. </view>
  12. <view style="margin: 0 40rpx;">
  13. <p style="margin-bottom: 20rpx;">上传作业数据截图</p>
  14. <htz-image-upload :max="1" mediaType="image" name="file" :chooseNum="1" v-model="imageData"
  15. @chooseSuccess="ceshiChooseSuccess1">
  16. </htz-image-upload>
  17. <p style="height: 50px;font-size: 32rpx;width: 100%;color: #808090;">上传作业数据截图(直播任务请上传销量截图)
  18. </p>
  19. </view>
  20. <view class="signup">
  21. <button type="default" class="but1" @click="submit()">
  22. 提交作业</button>
  23. </view>
  24. </view>
  25. <!-- <view v-if="onlyShow">
  26. <view style="margin: 20rpx;">
  27. <p>{{link_url}}</p>
  28. <view>
  29. <image :src="imageData" mode="scaleToFill"></image>
  30. </view>
  31. </view>
  32. </view> -->
  33. </view>
  34. </template>
  35. <script>
  36. import mvBar from "@/components/mys_navBar/mysNavBar";
  37. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  38. import getPolicyEncode from '@/components/obs/getPolicy.js';
  39. import getSignature from '@/components/obs/GetSignature.js';
  40. export default {
  41. components: {
  42. mvBar,
  43. htzImageUpload,
  44. },
  45. data() {
  46. return {
  47. onlyShow: false,
  48. navH: getApp().globalData.navHeight,
  49. taskId: "",
  50. link_url: "",
  51. imageData: [],
  52. assignmentStatus: "",
  53. mysNavConfig: {
  54. /* 开启单页显示首页图标 */
  55. isHome: true,
  56. /* 固定导航 */
  57. navFixed: true,
  58. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  59. navTitle: {
  60. text: "上传作业",
  61. color: "",
  62. fontSize: "32rpx", // px upx rpx
  63. fontWeight: "normal", // 100 - 700
  64. },
  65. btnType: "type2",
  66. onLeftClick: '',
  67. /* type2 按钮 */
  68. type2Config: {
  69. // 左图标
  70. leftPath: "/static/img/png2.png",
  71. // 右图标
  72. rightPath: "/static/img/png4.png",
  73. // 圆角
  74. radius: "40rpx",
  75. },
  76. },
  77. }
  78. },
  79. onLoad(options) {
  80. let data = options.textObj.replace(/""/g, "");
  81. data = JSON.parse(decodeURIComponent(data))
  82. this.taskId = data.taskId
  83. this.assignmentStatus = data.assignmentStatus
  84. },
  85. methods: {
  86. submit() {
  87. // 校验
  88. // if (this.link_url != "" && (this.link_url.substring(0, 8) != "https://" && this.link_url.substring(0, 7) !=
  89. // "http://")) {
  90. // uni.showToast({
  91. // title: '请输入正确的发布链接',
  92. // icon: 'none'
  93. // })
  94. // return
  95. // }
  96. if (this.imageData.length == 0) {
  97. uni.showToast({
  98. title: '请上传收录/发布截图',
  99. icon: 'none'
  100. })
  101. return
  102. }
  103. let that = this
  104. uni.showModal({
  105. title: '提示',
  106. content: '提交后无法修改并进行审核,确认提交?',
  107. success: async function(res) {
  108. if (res.confirm) {
  109. // 调用添加链接接口
  110. await that.addAssignmentApi()
  111. uni.navigateBack()
  112. } else if (res.cancel) {
  113. console.log('用户点击取消');
  114. }
  115. }
  116. });
  117. },
  118. addAssignmentApi() {
  119. return this.$https.post('/youngee/c/api/t/assignment/add', {
  120. task_id: this.taskId,
  121. link_url: this.link_url,
  122. photo_url: this.imageData[0],
  123. })
  124. .then(res => {})
  125. },
  126. ceshiChooseSuccess1(tempFilePaths, e) { //选择图片返回
  127. console.log('ceshiChooseSuccess', tempFilePaths, e);
  128. if (e == 0) {
  129. this.store = 'talent_upload/' + this.guid() + '.png'
  130. } else if (e == 1) {
  131. this.store = 'talent_upload/' + this.guid() + '.mp4'
  132. }
  133. /****************
  134. 以下代码是自定义上传逻辑,仅供参考
  135. ***************/
  136. this.imgUpload1(tempFilePaths);
  137. /*******************************/
  138. console.log("imgdata" + this.imageData)
  139. },
  140. imgUpload1(tempFilePaths) {
  141. let that = this
  142. console.log('imgUpload', tempFilePaths)
  143. let config = {
  144. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  145. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  146. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  147. };
  148. let fileName = this.store; //指定上传到OBS桶中的对象名
  149. // let fileName = "talent_upload/icon-arrow-right.png"
  150. let OBSPolicy = { //设定policy内容
  151. "expiration": "2089-12-31T12:00:00.000Z",
  152. "conditions": [{
  153. "bucket": "horastar"
  154. }, //Bucket name
  155. // {"bucket": "goin"},
  156. {
  157. 'key': fileName
  158. }
  159. ]
  160. }
  161. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  162. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  163. uni.uploadFile({
  164. //url: config.EndPoint,
  165. url: config.EndPoint,
  166. filePath: tempFilePaths[0],
  167. name: 'file',
  168. formData: {
  169. 'AccessKeyID': config.AccessKeyId,
  170. 'policy': policyEncoded,
  171. 'signature': signature,
  172. 'key': fileName,
  173. },
  174. success: function(res) {
  175. console.log(res.statusCode); //打印响应状态码
  176. if (res.statusCode == '204') {
  177. that.imageData.push(config.EndPoint + '/' + fileName);
  178. console.log('上传图片成功', res)
  179. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  180. console.log(obs_url)
  181. // that.formData.home_img = obs_url
  182. uni.showToast({
  183. title: '上传成功',
  184. icon: '成功'
  185. });
  186. } else {
  187. console.log('上传图片失败', res)
  188. uni.showToast({
  189. title: '上传失败',
  190. icon: '失败'
  191. });
  192. }
  193. },
  194. fail: function(e) {
  195. console.log(e);
  196. uni.showToast({
  197. title: '上传失败22222',
  198. icon: '失败'
  199. });
  200. }
  201. })
  202. },
  203. guid() {
  204. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  205. var r = Math.random() * 16 | 0,
  206. v = c == 'x' ? r : (r & 0x3 | 0x8);
  207. return v.toString(16);
  208. });
  209. },
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .signup {
  215. box-shadow: 0rpx 5rpx 40rpx #ccc;
  216. width: 100%;
  217. position: fixed;
  218. bottom: 0rpx;
  219. display: flex;
  220. height: 90rpx;
  221. padding-top: 2%;
  222. background-color: #FFFFFF;
  223. }
  224. .but1 {
  225. width: 60%;
  226. background-color: #f2d22d;
  227. border-radius: 20rpx;
  228. font-size: 36rpx;
  229. line-height: 200%;
  230. letter-spacing: 10rpx;
  231. font-weight: 500;
  232. height: 80%;
  233. &.on {
  234. background-color: #C0C0C0;
  235. }
  236. }
  237. </style>